internal TimerQueueTimer(
            TimerQueue queue,
            TimerCallback cb,
            object state,
            uint dueTime,
            uint period,
            TimerQueueTimerFlags flags)
        {
            MyQueue  = queue;
            Callback = cb;
            win32WaitOrTimerCallback = TimerCallback;
            UserState = state;
            bool rslt = TQTimerWin32.CreateTimerQueueTimer(
                out Handle,
                MyQueue.Handle,
                win32WaitOrTimerCallback,
                IntPtr.Zero,
                dueTime,
                period,
                flags);

            if (!rslt)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), "Error creating timer.");
            }
        }
 public TimerQueue()
 {
     Handle = TQTimerWin32.CreateTimerQueue();
     if (Handle == IntPtr.Zero)
     {
         throw new Win32Exception(Marshal.GetLastWin32Error(), "Error creating timer queue.");
     }
 }
        public void Change(uint dueTime, uint period)
        {
            bool rslt = TQTimerWin32.ChangeTimerQueueTimer(MyQueue.Handle, ref Handle, dueTime, period);

            if (!rslt)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), "Error changing timer.");
            }
        }
 protected virtual void Dispose(bool disposing)
 {
     if (!disposed)
     {
         bool rslt = TQTimerWin32.DeleteTimerQueueTimer(MyQueue.Handle,
                                                        Handle, completionEventHandle);
         if (!rslt)
         {
             throw new Win32Exception(Marshal.GetLastWin32Error(), "Error deleting timer.");
         }
         disposed = true;
     }
 }
 protected virtual void Dispose(bool disposing)
 {
     if (!Disposed)
     {
         if (Handle != IntPtr.Zero)
         {
             bool rslt = TQTimerWin32.DeleteTimerQueueEx(Handle, CompletionEventHandle);
             if (!rslt)
             {
                 int err = Marshal.GetLastWin32Error();
                 throw new Win32Exception(err, "Error disposing timer queue");
             }
         }
         Disposed = true;
     }
 }