public async Task StartCommandAsync(Func <ICommandStatus, Task> action, string maintext = null, string subtext = null) { var task = new RunningTask("console", maintext, subtext); if (!_tasks.TryGetValue("console", out TaskContext c)) { c = new TaskContext { Tasks = { task } }; _tasks.TryAdd("console", c); } else { lock (c) { c.Tasks.Add(task); } c.FireChanged(); } try { await action(task); task.Dispose(); } catch (Exception ex) { task.Exception = ex; } }
public async Task StartTaskAsync(Func <ITaskStatus, Task> action, string context = null, string maintext = null, string subtext = null) { if (context == null) { context = string.Empty; } var task = new RunningTask(context, maintext, subtext); if (!_dict.TryGetValue(context, out TaskContext c)) { c = new TaskContext { Tasks = { task } }; _dict.TryAdd(context, c); } else { lock (c) { c.Tasks.Add(task); } c.FireChanged(); } try { await action(task); task.Dispose(); } catch (Exception ex) { task.Exception = ex; if (DumpExceptionsToConsole) { Console.Error.Write(ex); } } }
public void Dispose() { RunningTask?.Dispose(); CancellationTokenSource?.Dispose(); }