private void HandleCompletedTask(Task t)
 {
     // notify non-success
     if (!t.IsCompletedSuccessfully)
     {
         TaskFaulted?.Invoke(this, t);
     }
 }
Example #2
0
        public async Task <bool> StartTask(string tempInputFolderPath, string tempOutputFolderPath, string waifu2xCaffePath, string ffmpegPath)
        {
            bool faulted = false;

            try
            {
                if (!Initialize())
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                TaskFaulted?.Invoke(this, $"Error occurred during initialization: {e.Message}");
                Logger.Error("An exception occurred during initialization: {@Exception}", e);
                faulted = true;
            }

            bool taskSucceeded = false;

            if (!faulted)
            {
                try
                {
                    taskSucceeded = await Start(tempInputFolderPath, tempOutputFolderPath, waifu2xCaffePath, ffmpegPath);
                }
                catch (Exception e)
                {
                    taskSucceeded = false;
                    TaskFaulted?.Invoke(this, $"Error occurred while processing: {e.Message}");
                    Logger.Error("An exception occurred while processing: {@Exception}", e);
                }
            }

            TaskCompleted?.Invoke(this);

            try
            {
                return(Dispose());
            }
            catch (Exception e)
            {
                if (!faulted)
                {
                    TaskFaulted?.Invoke(this, $"Error occurred while running cleanup: {e.Message}");
                }

                return(false);
            }
        }
Example #3
0
        public async Task <bool> CancelTask()
        {
            WasCanceled = true;

            try
            {
                if (!IsRunning)
                {
                    return(Dispose());
                }
            }
            catch (Exception e)
            {
                TaskFaulted?.Invoke(this, $"Error occurred while running cleanup: {e.Message}");
                Logger.Error(e, "Error occurred while running cleanup");
                return(false);
            }

            bool faulted = false;

            try
            {
                if (!(await Cancel()))
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                TaskFaulted?.Invoke(this, $"Error occurred while canceling a task: {e.Message}");
                Logger.Error(e, "Error occurred while canceling a task");
                faulted = true;
            }

            try
            {
                return(Dispose() && !faulted);
            }
            catch (Exception e)
            {
                TaskFaulted?.Invoke(this, $"Error occurred while running cleanup for a canceled task: {e.Message}");
                Logger.Error(e, "Error occurred while running cleanup for a canceled task");
                return(false);
            }
        }
        public void RaiseTaskFaulted(Task task, [CallerMemberName] string taskName = default)
        {
            var status = $"[Faulted] Task: {taskName}. status: {task.Status}".AppendMainThreadAlert();

            TaskFaulted?.Invoke(this, new TaskStatusChangedEventArgs(task, status));
        }
 private void OnTaskFaulted()
 {
     TaskFaulted?.Invoke(this, new ObservableTaskEventArgs(_task));
 }