Beispiel #1
0
        public static AsyncTask Create(string name, Action <AsyncTaskControl> action)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            var taskCompletionSource = new TaskCompletionSource <Unit>();
            var task      = taskCompletionSource.Task;
            var namedTask = new NamedTask(string.IsNullOrEmpty(name) ? "Task#" + task.Id : name, task);
            var control   = new AsyncTaskControl(namedTask, taskCompletionSource);

            return(new AsyncTask(namedTask, new Task(() => action(control), TaskCreationOptions.DenyChildAttach)));
        }
Beispiel #2
0
 AsyncTask(NamedTask task, Task inner)
 {
     _task  = task;
     _inner = inner;
 }
Beispiel #3
0
 public AsyncTaskControl(NamedTask task, TaskCompletionSource <Unit> completionSource)
 {
     Task = task;
     _completionSource = completionSource ?? throw new ArgumentNullException(nameof(completionSource));
 }