.net crossthreading trouble
i have such code, in callback function
try{
text.Invoke(new MethodInvoker(() => text.AppendText("te开发者_运维技巧st")));
}
catch (Exception e)
{
text.Invoke(new MethodInvoker(() => text.AppendText(e.Message)));
}
text is winforms.textbox and at the text.Invoke.. i have "Microsoft.VisualStudio.Debugger.Runtime.CrossThreadMessagingException" why? this way always worked for me.
I assume that //blahblahblah
does something that talks to one or more UI controls? Maybe to read/write values? That won't work, due to thread affinity. If you are talking to the UI controls, use Invoke
to get onto the UI thread earlier. You can of course query external data while on the background thread.
精彩评论