C-constructor RAD 2010 RTL / VCL Application-> Terminate () Function NOT TERMINATING APPLICATION

I also have the problem described here: http://www.delphigroups.info/3/9/106748.html

I tried almost all forms of placement Application-> Terminate () func everywhere in the code, following and not returning 0, ExitProcess (0) ',' ExitThread (0) ', exit (0). No working option closes the application. Instead, the code is executed after the Application-> Terminate () statement.

I have two or more threads in an application. I tried calling the terminate func created after the execution threads and in the main thread.

In addition, it is not (as far as I can imagine) connected with CodeGuard / madExcept (I turned it off and on, no effect). CodeGuard coding also failed.

The only working code option is to place a call to Application-> Terminate () in any of the OnClick handlers of any form. But this does not fit my needs. I need to stop working anywhere.

What should I do to complete all threads in a C ++ Builder 2010 application and then complete the process?

+4
source share
1 answer

Application-> Terminate () does not close the application immediately, it is only the signals that you want to close the application.

End the Windows API call PostQuitMessage function to perform an orderly closing of the application. The completion is not immediate.

In your functions, call Application-> ProcessMessages () , then check if Application-> Terminated is true.

For applications that use intensive computing, call Periodically process messages and also check completion to determine whether to abort the calculation and allow the application to complete

For instance:

void Calc() { for (int x = 0; x < 1000000; ++x) { // perform complex calculation // check if need to exit Application->ProcessMessages(); if (Application->Terminated) { break; } // end if } // end for // clean up } 
+3
source

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


All Articles