473,396 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 9573
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Jonathan Heath | last post by:
Hi all, I have created an ASP script that enters data into an Access Database. My problem is that I'd like this script to run when the computer is shutdown or the user logs off. I think...
0
by: Allan Bredahl | last post by:
Hi All I am trying to construct an application that is able to cancel a machine shutdown, reboot or logoff. And after performing some stuff to perform the original shutdown order :...
3
by: Senthil | last post by:
Hi, I would like to know the code for reboot and shutdown windows xp professional using VB.Net. thanx Senthil
4
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
2
by: Brian Worth | last post by:
I have just upgraded from VB 4.0 to VB .NET 2002. One program under VB 4.0 was able to shut down or restart the (windows XP) machine using a series of API calls. (Getlasterror, GetCurrentProcess,...
10
by: Steve | last post by:
Does any one know if python has the ability to run a shutdown hook. For example you set a method to run when the python process is shutting down, like it recieved a kill signal? Basically...
0
by: zeng.hui.stephen | last post by:
I download the demo http://msdn.microsoft.com/msdnmag/issues/02/10/cuttingedge/. I inherite the demo, and write my code. I want to use Hook to monitor C++ Edit change. I use a C# form...
5
by: Phil Tusa | last post by:
Greetings to all .... I have a need to issue a shutdown and/or Restart Windows XP inside my application. Any help or example code would be appreciated! -- Phil
22
by: schneider | last post by:
I need to hook the system mouse down event. I'm trying to replicate how a context menu hides when the mouse clicks outside of the control. Thanks, Schneider
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.