Esempio n. 1
0
 /// <summary>
 /// 更改计时器的启动时间和方法调用之间的间隔,用 32 位有符号整数度量时间间隔。
 /// </summary>
 /// <param name="dueTime">在调用构造 System.Threading.Timer 时指定的回调方法之前的延迟时间量(以毫秒为单位)。指定 System.Threading.Timeout.Infinite可防止重新启动计时器。指定零 (0) 可立即重新启动计时器。</param>
 /// <param name="period">调用构造 System.Threading.Timer 时指定的回调方法的时间间隔(以毫秒为单位)。指定 System.Threading.Timeout.Infinite可以禁用定期终止。</param>
 /// <returns>如果尚未释放当前实例,则为 true;否则为 false。</returns>
 public bool Change(int dueTime, int period)
 {
     using (ReaderWriterLockSlimAutoController write = new ReaderWriterLockSlimAutoController(locker, AutoLockPolicy.Write))
     {
         if (disposing == true)
         {
             return(false);
         }
         if (disposed == true)
         {
             throw new ObjectDisposedException(typeof(WrappedTimer).ToString());
         }
         return(m_Timer.Change(dueTime, period));
     }
 }
Esempio n. 2
0
 /// <summary>
 /// 释放 System.Threading.Timer 的当前实例使用的所有资源并在释放完计时器时发出信号。
 /// </summary>
 /// <param name="notifyObject">释放完 Timer 时要发出其信号的 System.Threading.WaitHandle。</param>
 /// <returns>如果函数成功,则为 true;否则为 false。</returns>
 public bool Dispose(WaitHandle notifyObject)
 {
     using (ReaderWriterLockSlimAutoController write = new ReaderWriterLockSlimAutoController(locker, AutoLockPolicy.Write))
     {
         if (disposing == true)
         {
             return(false);
         }
         disposing = true;
         if (disposed == true)
         {
             throw new ObjectDisposedException(typeof(WrappedTimer).ToString());
         }
         try
         {
             bool result = false;
             locker.ExitWriteLock();
             try
             {
                 result = m_Timer.Dispose(notifyObject);
                 notifyObject.WaitOne();
             }
             finally
             {
                 locker.EnterWriteLock();
             }
             m_Timer = null;
             return(result);
         }
         finally
         {
             disposing = false;
             disposed  = true;
         }
     }
 }