K
K
Kiril12212020-05-15 02:03:05
C++ / C#
Kiril1221, 2020-05-15 02:03:05

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.


All of the answers find this quote, but it's completely completely unsuitable for my situation. Yes, yes, I have Application.Run( new FormTest() ), the application is not a console one, there is nothing in main behind this call;
//main
//....
 Application.Run( new FormTest() );
}
////////////////////formtest.cs
FormTest(){
 try{
      //....................................................нету ни каких потоков, вылетает IOException сразу 
catch(Exception ex){
  Message.Show(ex.StackTrace,"Error",....);
Application.Exit();
}

}

Why does the program continue to work like nothing else. What is the meaning of this method.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rPman, 2020-05-15
@Kiril1221

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 question

Ask a Question

731 491 924 answers to any question