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))); }
AsyncTask(NamedTask task, Task inner) { _task = task; _inner = inner; }
public AsyncTaskControl(NamedTask task, TaskCompletionSource <Unit> completionSource) { Task = task; _completionSource = completionSource ?? throw new ArgumentNullException(nameof(completionSource)); }