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 4503
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: 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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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,...
|
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...
|
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...
|
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...
| |