How to make BackgroundWorker ProgressChanged events execute in sequence?

后端 未结 2 1192
情歌与酒
情歌与酒 2021-01-11 19:13

Consider the following code:

private static BackgroundWorker bg = new BackgroundWorker();

static void Main(string[] args) {
  bg.DoWork += bg_DoWork;
  bg.P         


        
2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-11 19:54

    BackgroundWorker raises ProgressChanged events on the current SynchronizationContext of the thread that called RunWorkerAsync().

    The default SynchronizationContext runs callbacks on the ThreadPool without any synchronization.

    If you use BackgroundWorker in a UI application (WPF or WinForms), it will use that UI platform's SynchronizationContext, which will execute callbacks in order.

提交回复
热议问题