How to kill the main thread?

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

Any ideas on how to stop this?

 MessageBox.Show("Servers overloaded. Exiting."); this.Close(); //...other code that processes even after it closes... 
+4
source share
3 answers

Closing the window does not stop the stream.

You can use Environment.Exit to shut down immediately.

+8
source

Unlike ASP.Net Response.End() calling Close does not cancel the thread.

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

+3
source

Why does it stop at Close() ? It is still going to exit your method - most things, such as Close() , will include sending something to the Windows message queue and processing it. If you need to exit NOW, then maybe Environment.FailFast ...

+2
source

Source: https://habr.com/ru/post/1301968/


All Articles