/// <summary> /// Closes the document /// </summary> public virtual void Close() { if (IsClosed) { return; } IsClosed = true; _textDocumentFactoryService.TextDocumentDisposed -= OnTextDocumentDisposed; DocumentClosing?.Invoke(this, null); if (EditorTree != null) { _editorTree.Dispose(); // this will also remove event handlers _editorTree = null; } if (DocumentClosing != null) { foreach (EventHandler <EventArgs> eh in DocumentClosing.GetInvocationList()) { Debug.Fail(String.Format(CultureInfo.CurrentCulture, "There are still listeners in the EditorDocument.OnDocumentClosing event list: {0}", eh.Target)); DocumentClosing -= eh; } } ServiceManager.RemoveService <REditorDocument>(TextBuffer); TextBuffer = null; }
async Task OnDocumentClosing(DocumentCloseEventArgs args) { try { if (DocumentClosing != null) { foreach (var handler in DocumentClosing.GetInvocationList().Cast <DocumentCloseAsyncEventHandler> ()) { await handler(this, args); if (args.Cancel) { break; } } } } catch (Exception ex) { LoggingService.LogError("Exception before closing documents", ex); } }