public async Task <string> StartTask(string name, int delay, int failAfter) { var tokenSource = new CancellationTokenSource(); string taskId = Guid.NewGuid().ToString(); var item = new TaskProperties(taskId, name, tokenSource); item.State = TaskState.Running; CurrentTasks.TryAdd(taskId, item); Clients.All.taskStarted(item); var task = SampleAsyncTask.StartCalculation(delay, failAfter, tokenSource.Token, new Progress <int>(percent => onProgressChange(taskId, percent))); // ReSharper disable CSharpWarnings::CS4014 task.ContinueWith(t => onTaskFinished(t, item), tokenSource.Token); task.ContinueWith(t => onTaskFinished(t, item), TaskContinuationOptions.OnlyOnCanceled); // ReSharper restore CSharpWarnings::CS4014 await task; return(taskId); }
public void AsyncTask00() { Assert.Throws<ArgumentNullException>(() => { // The first argument cannot be null. var task = new SampleAsyncTask(null); }); }