multithreading - C# Join() not return control after thread is over -


i have class this:

class someclass {     bool iswork;     thread workthread;      public void start()     {         iswork = true;         workthread = new thread(new threadstart(dowork));         workthread.setapartmentstate(apartmentstate.sta);         workthread.isbackground = true;         workthread.start();     }      public void stop()     {         iswork = false;         workthread.join();     } }  void dowork() {     while (iswork)     {         // work          thread.sleep(100);     } } 

when application starting create instance of someclass , call start() method. call stop() method of instance ui thread and:

  1. iswork set "false";
  2. main thread join workthread;
  3. workthread check isworked , finishet correctly;
  4. main thread freeze on workthread.join().

as understant joined thread should continue executing after workthread over, it's not true in situation.

at moment when main thread call workthread.join() workthread alive , exists in debug thread window. when application freeze workthread not exists.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -