开发者

.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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜