I'm working on a PIM program, which can function as an alarm clock. It needs
to be able to suspend the computer, and wake it up at a particular time.
As a test, I'm using a Waitable timer (through PInvoke'd Win32 calls) to
trigger an event, say, 30 seconds later. I create a timer, set its
properties, and then start a new thread to listen for the timer. However the
event triggers instantly, instead of waiting 30 seconds. Am I setting the
trigger time wrongly, or is something else the issue?
PInvoke Commands :
[DllImport("kernel32.dll")]
public static extern IntPtr CreateWaitableTimer(IntPtr lpTimerAttributes,
bool bManualReset, string lpTimerName);
[DllImport("kernel32.dll")]
public static extern bool SetWaitableTimer(IntPtr hTimer, [In] ref long
pDueTime, int lPeriod, TimerAPCProc pfnCompletionRoutine, IntPtr
lpArgToCompletionRoutine, bool fResume);
[DllImport("kernel32", SetLastError = true, ExactSpelling = true)]
public static extern Int32 WaitForSingleObject(IntPtr handle, Int32
milliseconds);
public static uint INFINITE = 0xFFFFFFFF;
The main code is :
private IntPtr handle;
private void shutdownToolStripMenuItem_Click(object sender, EventArgs e)
{
DateTime dt = DateTime.Now;
dt.AddSeconds(30.0);
long duetime = dt.ToFileTime();
handle = Win32.PowerManagement.CreateWaitableTimer(IntPtr.Z ero, true, "");
Win32.PowerManagement.SetWaitableTimer(handle, ref duetime, 0, null,
IntPtr.Zero, true);
Thread t = new Thread(new ThreadStart(this.NewThread));
t.Start();
}
private void NewThread()
{
int ret = Win32.PowerManagement.WaitForSingleObject(handle,
(int)Win32.PowerManagement.INFINITE);
MessageBox.Show("Wait object"); // ret = 0x00000000L here
}
Any help would be greatly appreciated.
Regards,
Chris 1 4500
Use a relative time, that is the time im multiples of 100nsec.
long duetime=-300000000; // wait 30 seconds to signal the handle.
Willy.
"Christopher Stott" <Christopher St***@discussions.microsoft.com> wrote in
message news:C6**********************************@microsof t.com... I'm working on a PIM program, which can function as an alarm clock. It needs to be able to suspend the computer, and wake it up at a particular time.
As a test, I'm using a Waitable timer (through PInvoke'd Win32 calls) to trigger an event, say, 30 seconds later. I create a timer, set its properties, and then start a new thread to listen for the timer. However the event triggers instantly, instead of waiting 30 seconds. Am I setting the trigger time wrongly, or is something else the issue?
PInvoke Commands :
[DllImport("kernel32.dll")] public static extern IntPtr CreateWaitableTimer(IntPtr lpTimerAttributes, bool bManualReset, string lpTimerName);
[DllImport("kernel32.dll")] public static extern bool SetWaitableTimer(IntPtr hTimer, [In] ref long pDueTime, int lPeriod, TimerAPCProc pfnCompletionRoutine, IntPtr lpArgToCompletionRoutine, bool fResume);
[DllImport("kernel32", SetLastError = true, ExactSpelling = true)] public static extern Int32 WaitForSingleObject(IntPtr handle, Int32 milliseconds); public static uint INFINITE = 0xFFFFFFFF;
The main code is :
private IntPtr handle;
private void shutdownToolStripMenuItem_Click(object sender, EventArgs e) { DateTime dt = DateTime.Now; dt.AddSeconds(30.0); long duetime = dt.ToFileTime();
handle = Win32.PowerManagement.CreateWaitableTimer(IntPtr.Z ero, true, ""); Win32.PowerManagement.SetWaitableTimer(handle, ref duetime, 0, null, IntPtr.Zero, true);
Thread t = new Thread(new ThreadStart(this.NewThread)); t.Start(); }
private void NewThread() { int ret = Win32.PowerManagement.WaitForSingleObject(handle, (int)Win32.PowerManagement.INFINITE); MessageBox.Show("Wait object"); // ret = 0x00000000L here }
Any help would be greatly appreciated.
Regards,
Chris This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Carlos Kirkconnell |
last post by:
I'm programming a multi - threaded application using C#. I have two
questions regarding to the use of threads
1- I have a Hashtable that will have multiple writters and multiple readers.
I used...
|
by: CMan |
last post by:
Hi,
We are currently trying to install .Net Framework v.1.1 on a server which
already has v1.0.
We are receiving the following error.
Error 1704.An installation for Microsoft .NET Framework...
|
by: Guido Kraus |
last post by:
Hi,
I have a VB Windows Forms app that has a single form ('MainForm'). MainForm
has a shared (C#: static) class variable that holds a reference to a newly
created Thread. This thread does some...
|
by: Lee |
last post by:
Hello.
I am trying to start a process in a suspended state in a c#
application. Unfortunately there seems to be no support for suspended
process creation in the Process class.
Does anyone...
|
by: Amratash |
last post by:
I'm receiving the above mentioned error.The problem is:
"I suspend one thread.Another thread is resuming the first thread.Then I
added following code:Its in simple english
if(first thread is not...
|
by: Andreas Müller |
last post by:
Hi All,
What I want to do, is to reuse a thread after it was supended. However,
if the thread was suspended for a while and I reinvoke it using
Thread.Resume(), an exception is thrown. If I look...
|
by: Brett |
last post by:
Once a thread is put into suspended mode, how is it restart? Calling
Thread.start() will throw an error.
Thanks,
Brett
|
by: Mark Denardo |
last post by:
I'm trying to abort a suspended thread, but I get a ThreadStateException:
An unhandled exception of type 'System.Threading.ThreadStateException'
occurred in mscorlib.dll
Additional...
|
by: Tim |
last post by:
Folks,
I have 3 loosely linked problems which I am would appreciate feedback
on.
1). T-Sql and Active directory roles.
We want to be able to control access to data within a table based on a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
| |