How can I stop a thread in C#?

前端 未结 4 1572
逝去的感伤
逝去的感伤 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 05:58

    You should use a boolean or a condition to stop the Thread. You can than use a Property to change the "Flag" of this boolean and the loop of the Thread will end. This is a proper way to do it. Of course, you can use Abort() on the Thread but this is not recommended and will raise an Exception that you will need to handle.

提交回复
热议问题