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:
- iswork set "false";
- main thread join workthread;
- workthread check isworked , finishet correctly;
- 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
Post a Comment