How can I stop a thread in C#?

前端 未结 4 1570
逝去的感伤
逝去的感伤 2021-01-16 05:27

I\'ve created a Client-Server application, and on the Server I want to have the oportunity to stop the server and then start it again. The problem is that I can\'t stop the

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-16 06:08

    possible from the outside Thread.Abort and there is a way to pause. but its an incorrect way to do it...

    you should just end the code to kill, reach the last } . and for pausing you should use a Mutex. the manner of opporation should be, you order the object to pause, and after it finishes with the current request it gets halt by the mutex before the next one. or just steps out side of the while for "kill".

    btw the MSDN has a nice article describing common threading scenarios

提交回复
热议问题