C#.net - How to alert program that the thread is finished (event driven)?

后端 未结 2 1359
南笙
南笙 2020-12-06 03:09

this is a snippet from my class:

public bool start()
{
   Thread startThread = new Thread(this.ThreadDealer);
   startThread.Start();
   return _start;
}
         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 03:24

    Just raise an event. It will run on the wrong thread so whatever event handler has to deal with that by marshaling the call if necessary to update any UI. By using Control.Begin/Invoke or Dispatcher.Begin/Invoke, depending what class library you use.

    Or use the BackgroundWorker class, it does it automatically.

提交回复
热议问题