471,319 Members | 1,226 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

How to implement shutdown hook ?

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.

Nov 27 '05 #1
4 9286
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"yaron" <ya***@discussions.microsoft.com> wrote in message
news:4D**********************************@microsof t.com...
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.

Nov 28 '05 #2
Hi Ignacio Machin,

is it good also for c# console applications ?

Thanks.
"Ignacio Machin ( .NET/ C# MVP )" wrote:
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"yaron" <ya***@discussions.microsoft.com> wrote in message
news:4D**********************************@microsof t.com...
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.


Nov 29 '05 #3
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"yaron" <ya***@discussions.microsoft.com> wrote in message
news:84**********************************@microsof t.com...
Hi Ignacio Machin,

is it good also for c# console applications ?

Thanks.
"Ignacio Machin ( .NET/ C# MVP )" wrote:
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"yaron" <ya***@discussions.microsoft.com> wrote in message
news:4D**********************************@microsof t.com...
> 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.
>


Nov 29 '05 #4
Thanks Ignacio Machin,

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

"Ignacio Machin ( .NET/ C# MVP )" wrote:
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"yaron" <ya***@discussions.microsoft.com> wrote in message
news:84**********************************@microsof t.com...
Hi Ignacio Machin,

is it good also for c# console applications ?

Thanks.
"Ignacio Machin ( .NET/ C# MVP )" wrote:
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"yaron" <ya***@discussions.microsoft.com> wrote in message
news:4D**********************************@microsof t.com...
> 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.
>


Nov 30 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Allan Bredahl | last post: by
10 posts views Thread by Steve | last post: by
reply views Thread by zeng.hui.stephen | last post: by
22 posts views Thread by schneider | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.