Пример #1
0
 public static Action InfinityAction(this Action ac, Action <Exception> exceptionhandler = null, CancellationTokenSource token = null, uint interval = 1, PauseTokenSource ptoken = null)
 {
     return(() =>
     {
         while (true)
         {
             if (token != null && token.IsCancellationRequested)
             {
                 return;
             }
             try
             {
                 if (ptoken != null && ptoken.pause)
                 {
                     continue;
                 }
                 ac.Invoke();
             }
             catch (Exception ex)
             {
                 exceptionhandler?.Invoke(ex);
             }
             finally
             {
                 Thread.Sleep((int)interval);
             }
         }
     });
 }
Пример #2
0
        public static Task InfinityTask(this Action ac, Action <Exception> exceptionhandler = null, CancellationTokenSource token = null, uint interval = 1, bool start = false, PauseTokenSource ptoken = null)
        {
            Task t = new Task(ac.InfinityAction(exceptionhandler, token, interval, ptoken));

            if (start)
            {
                t.Start();
            }
            return(t);
        }