private StatusDialog(Window owner, string title, BackgroundRequest request, HResult hr, string message, string errorPreamble, Action postAction) { instance = this; this.WindowStartupLocation = WindowStartupLocation.CenterOwner; this.Owner = owner; this.Title = title; this.ErrorStatus = new ErrorStatus(); this.ErrorStatus.Preamble = message; this.ErrorStatus.SetStatus(ErrorSeverity.Info, null, null); this.request = request; this.reportProgress = request as IReportProgress; this.DataContext = this; this.originalMessage = message; this.currentMessage = new MessageNode { Preamble = errorPreamble ?? StringResources.UnknownErrorOccurred, PostAction = postAction }; InitializeComponent(); if (request != null) { request.Dispatched += OnRequestDispatched; if (reportProgress != null) { reportProgress.Progress += OnProgressReport; } if (request.IsDispatchComplete) { // We were asked to wait on a request that has already been dispatched. Simulate notification // of the dispatch. Can't call it directly because Close() right now is bad news. this.Dispatcher.BeginInvoke((Action)(() => { this.OnRequestDispatched(request, EventArgs.Empty); }), DispatcherPriority.Background); } } else { SwitchToError(hr, false); } this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, OnCopyExecuted)); }
private StatusDialog(Window owner, string title, BackgroundRequest request, HResult hr, string message, string errorPreamble, Action postAction) { instance = this; this.WindowStartupLocation = WindowStartupLocation.CenterOwner; this.Owner = owner; this.Title = title; this.ErrorStatus = new ErrorStatus(); this.ErrorStatus.Preamble = message; this.ErrorStatus.SetStatus(ErrorSeverity.Info, null, null); this.request = request; this.reportProgress = request as IReportProgress; this.DataContext = this; this.originalMessage = message; this.currentMessage = new MessageNode { Preamble = errorPreamble ?? StringResources.UnknownErrorOccurred, PostAction = postAction }; InitializeComponent(); if (request != null) { request.Dispatched += OnRequestDispatched; if (reportProgress != null) { reportProgress.Progress += OnProgressReport; } if (request.IsDispatchComplete) { // We were asked to wait on a request that has already been dispatched. Simulate notification // of the dispatch. Can't call it directly because Close() right now is bad news. this.Dispatcher.BeginInvoke((Action)(() => { this.OnRequestDispatched(request, EventArgs.Empty); }), DispatcherPriority.Background); } } else { SwitchToError(hr, false); } this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, OnCopyExecuted)); }
void OnRequestDispatched(object sender, EventArgs e) { HResult hr = request.Result; request.Dispatched -= OnRequestDispatched; request = null; if (hr.Failed && hr != HResult.E_REQUEST_CANCELED && hr != HResult.E_REQUIRES_PROFILING_MODE) { SwitchToError(hr, false); } else { this.ignoreClose = false; this.Close(); } }
public static void DisplayWait(Window owner, string title, BackgroundRequest request, string message, string errorPreamble) { // Don't call this if there's already one in flight! Debug.Assert(instance == null); if (instance == null) { new StatusDialog(owner, title, request, HResult.S_OK, message, errorPreamble, null).ShowDialog(); } }
void OnRequestDispatched(object sender, EventArgs e) { HResult hr = request.Result; request.Dispatched -= OnRequestDispatched; request = null; if (hr.Failed && hr != HResult.E_REQUEST_CANCELED && hr != HResult.E_REQUIRES_PROFILING_MODE) { SwitchToError(hr, false); } else { this.ignoreClose = false; this.Close(); } }
internal void OnRequestDispatched(BackgroundRequest request) { if (observableRequestList != null) observableRequestList.Remove(request); }
public void Enqueue(BackgroundRequest request) { HResult hr = ((IBackgroundRequest)request).OnEnqueued(this); // If OnEnqueued returns failure, it means that the request will already have // dispatched its return value. No need to put it in the queue. if (hr.Succeeded) { if (observableRequestList != null) { if (!this.Dispatcher.CheckAccess()) { this.Dispatcher.BeginInvoke((Action)(() => observableRequestList.Add(request))); } else { observableRequestList.Add(request); } } lock (lockObject) { this.requests.Enqueue(request); this.workReadyEvent.Set(); } } }