开发者

How to kill the main thread?

Strange issue. I kill the main thread, but when the program ends, it still processes the code after this.Close().

Any ideas on how to stop that?

MessageBox.Show("Servers overloaded. Exiting.开发者_Python百科");
this.Close();
//...other code that processes even after it closes...


Closing the window does not stop the thread.

You can use Environment.Exit to shutdown immediately.


Unlike ASP.Net's Response.End(), calling Close will not abort the thread.

You need to add return; after calling Close() to exit the method.


Why would it stop at Close()? It is still going to exit your method - most things like Close() are going to involve sending something to the windows message queue and having it processed. If you need to exit NOW, then perhaps Environment.FailFast...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜