Sunday, 18 August 2013

Thread C# windows 8

Thread C# windows 8

[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, int
milliseconds);
public static uint INFINITE = 0xFFFFFFFF;
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.Zero, 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
}
How to implement this code in C# windows 8? That is, only this part:
Thread t = new Thread(new ThreadStart(this.NewThread));
t.Start();
Thanks!

No comments:

Post a Comment