static public void Use(RAII raii)
 {
     using (MyLockedResource resource = new MyLockedResource())
     {
         raii(resource);
     }
 }
示例#2
0
 public override void SchedulingRun(CancellationToken token)
 {
     while (!token.IsCancellationRequested)
     {
         ExceptionHelper.ExceptionCatcher(() =>
         {
             try
             {
                 ProcessBody(token);
             }
             catch (OperationCanceledException)
             {
                 //ignore
             }
         }, where : nameof(PeriodicTaskScheduling) + " for : '" + TaskName + "'");
         if (token.IsCancellationRequested)
         {
             return;
         }
         using (var waitingCts = new CancellationTokenSource())
             using (var tokenSubscriber = token.Register(waitingCts.Cancel))
                 using (var ctsAbsolvent = new RAII(() => _waitingCts = null))
                 {
                     var waitingToken = waitingCts.Token;
                     _waitingCts = waitingCts;
                     var interval = (IntervalCalculator ?? throw new ArgumentNullException(nameof(IntervalCalculator)))();
                     if (interval != TimeSpan.Zero && !token.IsCancellationRequested)
                     {
                         ThreadHelper.Sleep(interval ?? TimeSpanConstants.Infinite, waitingToken);
                     }
                 }
     }
 }