public override bool OnOptionsItemSelected(IMenuItem item) { Android_Content.ContentResolver cr = GetActivity().GetContentResolver(); switch (item.GetItemId()) { case POPULATE_ID: if (mPopulatingTask != null) { mPopulatingTask.Cancel(false); } mPopulatingTask = new PopulateAsyncTask(cr); mPopulatingTask.Execute((object[]) null); return true; case CLEAR_ID: if (mPopulatingTask != null) { mPopulatingTask.Cancel(false); mPopulatingTask = null; } AsyncTask<object, object, object> task = new ClearAsyncTask(cr); task.Execute((object[])null); return true; default: return base.OnOptionsItemSelected(item); } }
/// <summary> /// 撤销任务 /// </summary> private void Cancel() { if (task != null) { task.Cancel(); this.lsv.Items.Add("Task has been cancelled."); } }
private void Redraw(bool forceDraw) { if (forceDraw || _flinging) { Invalidate(); } else { _renderTask?.Cancel(true); _renderTask = PdfFile.GetPages(GetPageFromInclusive(_offSet.Y), GetPageToExclusive(_offSet.Y), _onPdfPageRenderListener); } }
/// <summary> /// Handles the <see cref="IFolderSystemContext.SelectedItemsChanged"/> event. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void SelectedItemsChangedEventHandler(object sender, EventArgs args) { if (_operationEnablementTask == null) { return; } // cancel any previous operation enablement queries _operationEnablementTask.Cancel(); // if selection is empty, there is no need to query operation enablement if (this.Selection.Equals(Desktop.Selection.Empty)) { _workflowEnablement = null; EventsHelper.Fire(_selectedItemsChanged, this, EventArgs.Empty); return; } // query for operation enablement asynchronously IDictionary <string, bool> enablement = null; _operationEnablementTask.Run( delegate { enablement = QueryOperationEnablement(this.Selection); }, delegate { _workflowEnablement = enablement; EventsHelper.Fire(_selectedItemsChanged, this, EventArgs.Empty); }, delegate(Exception e) { Platform.Log(LogLevel.Error, e); // still need to fire the event, so that enablement of tools is updated EventsHelper.Fire(_selectedItemsChanged, this, EventArgs.Empty); }); }
static void LogErrorAndCancel(AsyncTask asyncTask, Exception exc) { asyncTask.LogCodedError("XA0000", Properties.Resources.XA0000_Exception, exc); asyncTask.Cancel(); }