This project is read-only.

Invoke and UI Threading

Jul 23, 2010 at 6:49 PM
Edited Jul 23, 2010 at 8:47 PM

I'm using a backgroundworker thread to write some text to the scintillaNet UI but it keeps crashing the backgroundworker thread.  Here's the code:


       for ( int i = 0; i < context.Count; i++ )
            scintilla1.Invoke( new DWriteToRBX( WriteToRBX ), ( i + 1 ) + ") " + context[ i ] + "\r\n" );

        private delegate void DWriteToRBX( string text );
        private void WriteToRBX( string text )
            scintilla1.AppendText( text );


If I replace scintilla1 with richTextBox1 then the RTB works fine.


As a workaround, I'm able to invoke another UI control on the same thread as the Scintilla control and then push the text through via the same delegate as posted above.

Jul 25, 2010 at 3:52 AM
A couple questions: What version of ScintillaNET and SciLexer.dll are you using? For the background thread that crashes, is there an exception and stack trace?
Jul 27, 2010 at 4:20 PM

I'm using version 2.2.  I just downloaded it the other day for the first time.  I guess "crash" isn't the appropriate word.  The thread halts but doesn't actually return an error.  If I attempt to invoke where an error is guaranteed, such as at startup before the window handle has been created, all other invocations (textbox, richtextboxes, etc.) throw an error.  The Scintilla editor, however, invokes and then keeps running as if it has worked properly.



        public MainForm()
            //should throw an InvalidOperationException
            scintilla1.Invoke( new DUpdateTextbox( UpdateTextbox ), "hey there" );




Aug 2, 2010 at 5:38 PM

My best guess is that Control.Invoke ends up sending a Window message that gets eaten either by ScintillaNet's message handling or Scintilla's. Have you tried an Invoke at a later time, long after any initialization happens?