Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Abort entire application from thread in delphi

I have a major problem with my delphi App. I'm developing a software that uses external security. I'm using usb devices that must be connected to the users machine in order for my software to run. If by any chance the user removes this dongle, or starts without it, the app is supposed to warn the user and stop immediately. A thread is being released at the creation of the app, which checks for the security device. However, when the checks fail, e.g. no device found, that thread is not killing my app. I'm using something like this:

    retCode := checkSecurity();
    if retCode = -1 then
    begin
        ShowMessage('Security device not found! Terminating immediately!');
        Application.Terminate;
    end;

The major problem here is that Application.Terminate doesn't really kill the app. I've read on SO and other places that the Terminate sends a signal for a gracefull shutdown and waits for other threads, in my case the main thread of the app, to finish. I really need to kill the app as mentioned, killing all threads and exiting, if possible, cleaning up to avoid memory leakage, but if not, fine with me. I'm using Delphi XE2, developing with Windows 8.1.

Any ideas?

like image 203
Raoni Medinilha Avatar asked Jan 17 '26 02:01

Raoni Medinilha


2 Answers

You can call ExitProcess to force immediate termination. In comparison to Halt, the OS function ExitProcess performs even less clean up.

like image 65
David Heffernan Avatar answered Jan 19 '26 17:01

David Heffernan


To kill an app, just call Halt. It's a leftover from the DOS times, adapted to work nicely with modern Delphi apps. It will call all 'finalization' blocks in all units but not much more.

like image 31
gabr Avatar answered Jan 19 '26 18:01

gabr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!