Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: BackgroundWorker

1 view
Skip to first unread message

霧雨魔理沙

unread,
May 25, 2011, 11:45:37 AM5/25/11
to
http://stackoverflow.com/questions/2806814/c-backgroundworker-runworkercomple
ted-event

If the BackgroundWorker was created from the UI thread, then the
RunWorkerCompleted event will also be raised on the UI thread.

If it was created from a background thread, the event will be raised on an
undefined background thread (not necessarily the same thread, unless you're
using a custom SynchronizationContext).

Interestingly, this doesn't seem to be all that well-documented on MSDN.
The best reference I was able to find was here:

The preferred way to implement multithreading in your application is to
use the BackgroundWorker component. The BackgroundWorker component uses an
event-driven model for multithreading. The background thread runs your
DoWork event handler, and the thread that creates your controls runs your
ProgressChanged and RunWorkerCompleted event handlers. You can call your
controls from your ProgressChanged and RunWorkerCompleted event handlers.



在 ncudeutjssbb (ncudeutjssbb) 的大作中提到: 】
: 长期以来,我一直以为BackgroundWorker的RunWorkerCompleted的handler是在主线程
: 中运行的。因为在RunWorkerCompleted的handler中能够对UI控件进行处理,而不需要任何
: 特殊设置。而且网上的资料也都是这么说的,看上去这个结论很合理,因此我对此确信不
: 疑。
: 今晚手痒随便做了个实验,却令我大跌眼镜。废话不多说,直接上源代码:
: using System;
: using System.ComponentModel;
: using System.Threading;
: namespace 多线程实验2
: {
: .................(以下省略)

--
普通の黒魔法少女·恋色マスタースパーク
恋符「マスタースパーク」 魔砲「ファイナルスパーク」
魔理沙 「ああ、私? そうだな、博丽霊梦、巫女だぜ」

[m [1;33m※ 来源:·饮水思源 bbs.sjtu.edu.cn·[FROM: 220.242.154.221] [m

0 new messages