S
Sin Jeong-hun
I created a windows form application. It has a Threading.Timer and when
the timer ticks it does some work and show a popup window.
The problem is that while this program is running if the user tries to
shutdown Windows, my application doesn't quit and neither does
Windows. Of course, if the user first click [X] of my application and
then tries to shutdown, there is no problem.
To solve this problem, I overrode WndProc of the main form, and add
some code like
IF the message = WM_ENDSESSION
Message.Result = IntPtr.Zero <-MSDN says that I should return 0
TheTimer.Dispose() <-TheTimer is a Threading.Timer
Application.ExitThreads()
Application.Exit()
Now when tried to shutdown, my application quits but Windows doesn't.
As a workaround I added the following precedures like
...
ExitWindows() <--This shutsdown Windows
It seems working but the problem is that I cannot know whether
WM_ENDSESSION is fired by Shutdown or Restart. MSDN says "it is not
possible to determine which event is occurring". So currently, if the
user Restart while my application is running, Windows will just
shutdown.
Do you see what the problem is? Why doesn't Windows shutdown even
though I returned 0 to the WM_ENDSESSION message and terminated my
application? If you have any idea, please let me know. Thank you.
the timer ticks it does some work and show a popup window.
The problem is that while this program is running if the user tries to
shutdown Windows, my application doesn't quit and neither does
Windows. Of course, if the user first click [X] of my application and
then tries to shutdown, there is no problem.
To solve this problem, I overrode WndProc of the main form, and add
some code like
IF the message = WM_ENDSESSION
Message.Result = IntPtr.Zero <-MSDN says that I should return 0
TheTimer.Dispose() <-TheTimer is a Threading.Timer
Application.ExitThreads()
Application.Exit()
Now when tried to shutdown, my application quits but Windows doesn't.
As a workaround I added the following precedures like
...
ExitWindows() <--This shutsdown Windows
It seems working but the problem is that I cannot know whether
WM_ENDSESSION is fired by Shutdown or Restart. MSDN says "it is not
possible to determine which event is occurring". So currently, if the
user Restart while my application is running, Windows will just
shutdown.
Do you see what the problem is? Why doesn't Windows shutdown even
though I returned 0 to the WM_ENDSESSION message and terminated my
application? If you have any idea, please let me know. Thank you.