473,395 Members | 1,986 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,395 software developers and data experts.

Threading.Timer & System Shutdown Problem

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.

Oct 27 '06 #1
2 2542
Can you post you code so someone here can perhaps easy to try it for you?

chanmm

"Sin Jeong-hun" <ty*******@gmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
>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.

Oct 28 '06 #2
I could, but maybe listing all the source code would be confusing to
the readers. That's why I just explained my code in psudocode. Anyways,
here is the real code.

public partial class MainForm : Form
{
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0016)
{
StopTimer();
TheTimer.Dispose();
TheNotifier.Close();
TheNotifier.Dispose();
m.Result = IntPtr.Zero;
Application.ExitThread();
Shutdown.DoExitWin(Shutdown.EWX_SHUTDOWN);
}
else
{
base.WndProc(ref m);
}
}

chanmm wrote:
Can you post you code so someone here can perhaps easy to try it for you?

chanmm

"Sin Jeong-hun" <ty*******@gmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
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.
Oct 28 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: David | last post by:
I've written a small windows service, and I'm having a problem that I'm spending a lot more time on than I'd like. If anyone has experienced this problem and has any hints or solutions; they would...
0
by: Rajesh Abraham | last post by:
I am looking to use Timers in my Windows Service application and just realised that apart from the forms Timer, there is also System.Threading,Timer and System.Timers.Timer. When should I prefer...
3
by: ELO | last post by:
Hi all Every week, I need to get two files on a remote server. I have developped a C# Windows Service with two System.Threading.Timer to do this task For the first one, the delay (TimeSpan...
4
by: Hagay Lupesko | last post by:
Hi, I've encountered a strange phenomena which appears to me as a bug: I have an engine that uses a System.Threading.Timer to invoke a delegate every X minutes. The code looks something...
6
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a...
2
by: KSC | last post by:
Hello, I have used a thread timer as in the documentation on MSDN in my VB.NET application. Using System.Threading.Interlocked.Increment I increment the counter to a certain point, perform an...
4
by: Giovanni | last post by:
Hi All, I need help with the following: Using VB.NET 2005, I am building a custom class in a separate assembly. The purpose of this class is to poll the internet to determine connectivity. I...
5
by: CCLeasing | last post by:
For an application I'm creating I want to create a 'fake' progress bar. By fake I mean a progress bar that looks like it's doing something but actually isn't. I know philosophically this isn't...
6
by: ewokspy | last post by:
I have a C# program in 2003 that creates a reminder bubble (windows form) to remind a user to pick up their printout. The bubbles show up fine, and they have 2 buttons, a yes and a snooze. The yes...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.