Exemple #1
0
        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;
            }
        }
Exemple #2
0
        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);
                }
            }
        }
Exemple #3
0
 public void Dispose()
 {
     RunningTask?.Dispose();
     CancellationTokenSource?.Dispose();
 }