Schedule() public abstract method

Schedules the specified run.
public abstract Schedule ( System.Action run ) : void
run System.Action The run.
return void
示例#1
0
        /// <summary>
        /// Schedules the specified run and returns a continuation task.
        /// </summary>
        public static Task <T> ScheduleAsync <T>(this MessageDispatcher dispatcher, Func <T> fn)
        {
            var promise = new TaskCompletionSource <T>();

            dispatcher.Schedule(() =>
            {
                try
                {
                    var result = fn();
                    promise.SetResult(result);
                }
                catch (Exception e)
                {
                    promise.SetException(e);
                }
            });

            return(promise.Task);
        }
示例#2
0
        protected override void Warmup(MessageDispatcher dispatcher)
        {
            var warmupCount = 10L;
            var warmupsThusFar = 0L;
            Action warmupWork = () =>
            {
                if (Interlocked.Increment(ref warmupsThusFar) == warmupCount)
                {
                    EventBlock.Set();
                }
            };


            for (var i = 0; i < warmupCount;)
            {
                dispatcher.Schedule(warmupWork);
                ++i;
            }
            EventBlock.Wait();
            EventBlock.Reset();
        }