Exemplo n.º 1
0
 private static CancellableTimout ScheduleInternal(Action action, int delay, SynchronizationContext syncCtx)
 {
     var c = new CancellableTimout();
     c.action = action;
     c.syncCtx = syncCtx;
     var t = new Timer(state =>
     {
         var cc = (CancellableTimout)state;
         var a = cc.action;
         if (a != null)
         {
             if (cc.syncCtx != null)
             {
                 syncCtx.Post(new SendOrPostCallback(z =>
                 {
                     using (cc)
                     {
                         if (cc.action != null) a();
                     }
                 }), null);
                 return;
             }
             else
             {
                 a();
             }
         }
         cc.Dispose();
     }, c, delay, Timeout.Infinite);
     c.timer = t;
     c.delay = delay;
     return c;
 }
Exemplo n.º 2
0
        private static CancellableTimout ScheduleInternal(Action action, int delay, SynchronizationContext syncCtx)
        {
            var c = new CancellableTimout();

            c.action  = action;
            c.syncCtx = syncCtx;
            var t = new Timer(state =>
            {
                var cc = (CancellableTimout)state;
                var a  = cc.action;
                if (a != null)
                {
                    if (cc.syncCtx != null)
                    {
                        syncCtx.Post(new SendOrPostCallback(z =>
                        {
                            using (cc)
                            {
                                if (cc.action != null)
                                {
                                    a();
                                }
                            }
                        }), null);
                        return;
                    }
                    else
                    {
                        a();
                    }
                }
                cc.Dispose();
            }, c, delay, Timeout.Infinite);

            c.timer = t;
            c.delay = delay;
            return(c);
        }