Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.");
this.Close();
//...other code that processes even after it closes...
like image 458
James Jeffery Avatar asked Dec 12 '22 23:12

James Jeffery


2 Answers

Closing the window does not stop the thread.

You can use Environment.Exit to shutdown immediately.

like image 196
Reed Copsey Avatar answered Dec 15 '22 12:12

Reed Copsey


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.

like image 24
SLaks Avatar answered Dec 15 '22 14:12

SLaks