示例#1
0
 protected static void PrepareDCObject(DelayedCall dc, int milliseconds, bool async)
 {
     if (milliseconds < 0)
     {
         throw new ArgumentOutOfRangeException("milliseconds", "The new timeout must be 0 or greater.");
     }
     dc.context = null;
     if (!async)
     {
         dc.context = SynchronizationContext.Current;
         if (dc.context == null)
         {
             throw new InvalidOperationException("Cannot delay calls synchronously on a non-UI thread. Use the *Async methods instead.");
         }
     }
     if (dc.context == null)
     {
         dc.context = new SynchronizationContext();
     }
     dc.timer = new System.Timers.Timer();
     if (milliseconds > 0)
     {
         dc.timer.Interval = (double)milliseconds;
     }
     dc.timer.AutoReset = false;
     dc.timer.Elapsed  += new ElapsedEventHandler(dc.Timer_Elapsed);
     DelayedCall.Register(dc);
 }
示例#2
0
 public void Start()
 {
     lock (this.timerLock)
     {
         this.cancelled = false;
         this.timer.Start();
         DelayedCall.Register(this);
     }
 }