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.Dispos e() <-TheTimer is a Threading.Timer
Application.Exi tThreads()
Application.Exi t()
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. 2 2561
Can you post you code so someone here can perhaps easy to try it for you?
chanmm
"Sin Jeong-hun" <ty*******@gmai l.comwrote in message
news:11******** **************@ k70g2000cwa.goo glegroups.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.Dispos e() <-TheTimer is a Threading.Timer
Application.Exi tThreads()
Application.Exi t()
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.
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.Dispos e();
TheNotifier.Clo se();
TheNotifier.Dis pose();
m.Result = IntPtr.Zero;
Application.Exi tThread();
Shutdown.DoExit Win(Shutdown.EW X_SHUTDOWN);
}
else
{
base.WndProc(re f m);
}
}
chanmm wrote:
Can you post you code so someone here can perhaps easy to try it for you?
chanmm
"Sin Jeong-hun" <ty*******@gmai l.comwrote in message
news:11******** **************@ k70g2000cwa.goo glegroups.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.Dispos e() <-TheTimer is a Threading.Timer
Application.Exi tThreads()
Application.Exi t()
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.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 be appreciated.
Simply leaving the threadMain() method if something unexpected occurs during
thread execution leaves the thread in a ThreadState.Running state. This
(apparently??) causes the Thread.Join() in service.OnStop() to hang...
|
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 one over the
other.
Also the subject of deleagates and callback has always
been confusing to me. Can someone direct me to some good
articles to make my fundas clear. Also suggest any good
books on the subject of Dealegates, CallBack, threading
|
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 dueTime) is always set to 6 days, 23 hours, 59 minutes, ..
Some weeks ?!?, the timer restarts immediately after its execution (and loop indefinitely). I have made a lot of tests and this issue does not occur with a delay < 1 day ..
Any suggestion
|
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 like this:
TimerCallback callBack = new TimerCallback(Run); // run is obviously a
method
|
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 TimerState object similar to the
example in the System.Threading.Timer documentation. The method which
handles the timer events, among other things, periodically calls a method in
this TimerState object which raises an event to the startup form,...
| |
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 operation, then dispose of the TimerReference. In
this case, the operation is simply enabling a checkbox control.
I have found that the timer will continue to tick at least twice after it is
disposed. Sometimes it will tick several HUNDRED...
|
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 have that part functioning
properly using HTTPRequest and HTTPResponse.
The problem lies here: I'd like to execute this monitoring on an
interval (Ex.: every 5 minutes), to get an up-to-date status. This updated
status would then be...
|
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 sound. But my little app is a 'fake'
app and is designed to look like another - hence this seeming crazy
situation of needing to fake a progess bar.
PROBLEM.
|
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 resynchs the thread. The snooze puts the bubble to sleep for 5 minutes.
Originally my event handler code for the snooze button pointed to the following method:
public void SnoozeForm(int minutes)
{
//VAR
TimeSpan waitLength =...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |