Answer the question
In order to leave comments, you need to log in
Why is Application.Exit not working, what is the point of this method?
Environment.Exit - from MSDN. Ends this process and provides the underlying operating system with the specified exit code. This is the code to call when you are using a console application.
Application.Exit - From MSDN: Tells all message handlers to exit and then closes all application windows after the messages have been processed. This code is used if you called Application.Run (WinForms applications), this method stops all running message loops on all threads and closes all application windows. There are still some issues with this method, read about it on the MSDN page.
//main
//....
Application.Run( new FormTest() );
}
////////////////////formtest.cs
FormTest(){
try{
//....................................................нету ни каких потоков, вылетает IOException сразу
catch(Exception ex){
Message.Show(ex.StackTrace,"Error",....);
Application.Exit();
}
}
Answer the question
In order to leave comments, you need to log in
Application.Exit is not such a deadly command, it is impossible to call it from the constructor, you can set your own boolean flag for the need to exit and call this method from Form_Load (so that the form does not appear briefly, you can make it hidden in the constructor or in the properties, but on Form_Load enable display).
For example Environment.Exit(0) works anyway but be careful, destructors may not be called.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question