示例#1
0
        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);
        }
示例#2
0
        public void CancelTask(CancelableTask task)
        {
            if (task.CancelTokenSource != null && !task.CancelTokenSource.IsCancellationRequested)
            {
                task.CancelTokenSource.Cancel();
            }

            if (mTaskList.Contains(task))
            {
                mTaskList.Remove(task);
            }
            CheckIfNeedHideNetworkIndicator();
        }