How to implement shutdown hook ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I am developing an infrastructure dll in c#.
my dll can be use by all kind of application containers win/web/console.
how do i implement a shutdown hook which will be called when the user exit
from the application (for all kind of .NET applications)?

for example in c# console application i do this with win32 interop
SetConsoleCtrlHandler function, but how do i know what kind of application
loaded my dll.

Thanks.
 
Hi,

You have to detect the windows messages your app receive when the system is
going down, I do not remember the names ( you could search for it either in
google of in the .h files ) I do interact with the logoff event, for this I
use WM_ENDSESSION/ WM_QUERYENDSESSION

Take a look at the MSDN about them


cheers,
 
Hi,

I do not think so, a Console app does not have a message pump, so you get
no messages from the OS, no idea how to do it in that case

cheers,
 
Thanks Ignacio Machin,

for console you can do it with SetConsoleCtrlHandler , see GC.KeepAlive
method sample in the MSDN help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top