Animatroller.Framework.Effect2.MasterEffect.CustomJob C# (CSharp) Method

CustomJob() public method

Run custom action on the effect timer
public CustomJob ( Action jobAction, System.Action jobStopped, int speed ) : Task
jobAction Action The action
jobStopped System.Action
speed int 0 = fastest, every 25 ms. 1 = every 50 ms, etc
return Task
        public Task CustomJob(Action<int> jobAction, Action jobStopped, int speed)
        {
            var taskSource = new TaskCompletionSource<bool>();

            if (jobAction == null)
                throw new ArgumentNullException("jobAction");

            CancellationTokenSource cancelSource = null;

            var observer = Observer.Create<int>(
                onNext: pos =>
                {
                    jobAction.Invoke(pos);
                },
                onCompleted: () =>
                {
                    jobStopped();
                    taskSource.SetResult(true);
                });

            cancelSource = this.timerJobRunner.AddTimerJobCounter(observer, speed);

            Executor.Current.SetManagedTask(taskSource.Task, cancelSource);

            return taskSource.Task;
        }