public CancelableTask AddTask(Task task, CancellationTokenSource cancellationTokenSource) { CancelableTask cancelableTask = new CancelableTask(); cancelableTask.Task = task; cancelableTask.CancelTokenSource = cancellationTokenSource; mTaskList.Add(cancelableTask); Mvx.Resolve <IPlatformService>().ShowNetworkIndicator(); try { task.ContinueWith((Task arg1, object arg2) => { mTaskList.Remove(cancelableTask); CheckIfNeedHideNetworkIndicator(); }, TaskContinuationOptions.NotOnCanceled); } catch (Exception ex) { mTaskList.Remove(cancelableTask); CheckIfNeedHideNetworkIndicator(); } return(cancelableTask); }
public void CancelTask(CancelableTask task) { if (task.CancelTokenSource != null && !task.CancelTokenSource.IsCancellationRequested) { task.CancelTokenSource.Cancel(); } if (mTaskList.Contains(task)) { mTaskList.Remove(task); } CheckIfNeedHideNetworkIndicator(); }