Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="funcIsContinue">if return ture then continue</param>
        public static CtkTask RunLoop(Func <bool> funcIsContinue, int sleep = 0)
        {
            var task = new CtkTask();

            task.Sleep = sleep;

            var ct = task.CancelTokenSource.Token;

            task.Task = Task.Factory.StartNew(() =>
            {
                task.SetupThreadName();
                while (!ct.IsCancellationRequested)
                {
                    ct.ThrowIfCancellationRequested();
                    if (!funcIsContinue())
                    {
                        break;
                    }
                    if (task.Sleep > 0)
                    {
                        Thread.Sleep(task.Sleep);
                    }
                }
            }, ct);

            return(task);
        }
Exemplo n.º 2
0
        public static CtkTask RunOnce(Action act, int sleep = 0)
        {
            var task = new CtkTask();

            task.Sleep = sleep;

            task.Task = Task.Factory.StartNew(() =>
            {
                task.SetupThreadName();
                act();
                if (task.Sleep > 0)
                {
                    Thread.Sleep(task.Sleep);
                }
            });
            return(task);
        }
Exemplo n.º 3
0
        public static CtkTask RunOnce(Action <CancellationToken> act, int sleep = 0)
        {
            var task = new CtkTask();

            task.Sleep = sleep;

            var ct = task.CancelTokenSource.Token;

            task.Task = Task.Factory.StartNew(() =>
            {
                task.SetupThreadName();
                act(ct);
                if (task.Sleep > 0)
                {
                    Thread.Sleep(task.Sleep);
                }
            }, ct);

            return(task);
        }