public override void DoCommand(object sender, EventArgs args) { var dlg = new DiagnosticsForm(_serviceProvider, "Gathering data..."); ThreadPool.QueueUserWorkItem(x => { var data = GetData(); try { dlg.BeginInvoke((Action)(() => { dlg.Ready(data); })); } catch (InvalidOperationException) { // Window has been closed already } }); dlg.ShowDialog(); }
public override void DoCommand(object sender, EventArgs args) { var dlg = new DiagnosticsForm(_serviceProvider, "Gathering data..."); ThreadPool.QueueUserWorkItem(x => { string data; try { data = GetData(); } catch (Exception ex) when(!ex.IsCriticalException()) { data = ex.ToUnhandledExceptionMessage(GetType()); } try { dlg.BeginInvoke((Action)(() => { dlg.Ready(data); })); } catch (InvalidOperationException) { // Window has been closed already } }); dlg.ShowDialog(); }