开发者

Multithreading: how to specify responsibility of newly created thread [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and po开发者_如何学Pythonssibly reopened, visit the help center for guidance. Closed 10 years ago.

I'm very new to multithreading and I'm getting kind of confused! Ok, so suppose I create another thread besides the main thread in my program. That thread should be responsible of updating the UI while the main thread does calculations and other stuff. My question how does that newly created thread know it's responsible for updating the UI? How do you specify that?


Only one thread is allowed to update the UI, and that is the main thread. You can use BackgroundWorker to do the secondary work. It can "report progress" or "complete work" and on those events pass a message back to the main thread to do the work.


Only the UI thread can update the UI.

If you are in another thread you'll need to pass it to the UI thread.

string newText = "New Text Here"; //Your thread
this.Invoke((MethodInvoker)delegate {
    Label1.Text = newText; // UI thread
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜