Exemplo n.º 1
0
        public static RunnableTask RunTaskTimer(Action runnable, int timerMillis, int executionCount)
        {
            int executionTimes = -1;

            RunnableTask runnableTask = new RunnableTask();

            runnableTask.Runnable = () =>
            {
                if (timerMillis > 0)
                {
                    Thread.Sleep(timerMillis);
                }

                //Allow infinite executions with a count of -1
                while (!runnableTask.Cancelled && (executionCount == -1 || ++executionTimes < executionCount))
                {
                    Thread.Sleep(timerMillis);

                    runnable.Invoke();
                }
            };

            _RunTask(runnableTask);

            return(runnableTask);
        }
Exemplo n.º 2
0
        //

        public static RunnableTask RunTask(Action runnable)
        {
            RunnableTask runnableTask = new RunnableTask(runnable);

            _RunTask(runnableTask);

            return(runnableTask);
        }
Exemplo n.º 3
0
        private static void _RunTask(RunnableTask runnable)
        {
            var runnableId = GetNextId();

            runnable.RunnableId = runnableId;

            ActiveRunnables.TryAdd(runnableId, runnable);

            ThreadPool.QueueUserWorkItem(runnable.ThreadPoolCallback);
        }
Exemplo n.º 4
0
        public static RunnableTask RunTaskLater(Action runnable, int delayMillis)
        {
            RunnableTask runnableTask = new RunnableTask(() =>
            {
                if (delayMillis > 0)
                {
                    Thread.Sleep(delayMillis);
                }

                runnable.Invoke();
            });

            _RunTask(runnableTask);

            return(runnableTask);
        }
Exemplo n.º 5
0
 public static void CancelRunnable(RunnableTask runnable)
 {
     CancelRunnable(runnable.RunnableId);
 }