void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { try { var markUpException = e.Exception as System.Windows.Markup.XamlParseException; if (markUpException != null) { var message = new Dictionary <string, string>(); message.Add("mesasge", markUpException + ""); //message.Add("file", ((e.Exception as System.Windows.Markup.XamlParseException)).BaseUri +""); //message.Add("line", ((e.Exception as System.Windows.Markup.XamlParseException)).LineNumber + ""); var rtlException = markUpException.InnerException as System.Reflection.ReflectionTypeLoadException; if (rtlException != null) { rtlException.LoaderExceptions.ToList().Select((le, i) => { message.Add("Errors[" + i + "]", le.Message); return(0); }).ToArray(); } AsyncMessageBox.BeginMessageBoxAsync(string.Join(Environment.NewLine + Environment.NewLine, message.Select(kv => kv.Key + ":" + kv.Value))); } else { FileLogger.LogToFile("App_DispatcherUnhandledException"); FileLogger.LogToFile(e.Exception); //AsyncMessageBox.BeginMessageBoxAsync(e.Exception + ""); } } catch (ObjectDisposedException) { AsyncMessageBox.BeginMessageBoxAsync(e.Exception + ""); } if (!(e.Exception is System.Windows.Markup.XamlParseException)) { e.Handled = true; } }
void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e) { try { GalaSoft.MvvmLight.Messaging.Messenger.Default.Send <LogMessage>(new LogMessage(e.Exception)); } catch { } if (!IsHandled(e.Exception)) { AsyncMessageBox.BeginMessageBoxAsync(e.Exception.ToString()); } }
void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { var exc = (Exception)e.ExceptionObject; try { GalaSoft.MvvmLight.Messaging.Messenger.Default.Send(new LogMessage(exc)); } catch { } FileLogger.LogToFile(exc); AsyncMessageBox.BeginMessageBoxAsync(string.Join("\n", ((Exception)e.ExceptionObject).Inners().Reverse().Select(ex => ex + ""))); }
App() { ReactiveUI.MessageBus.Current.Listen <WwwWarningMessage>().Subscribe(wm => WwwMessageWarning.Add(wm.Message)); DataFlowProcessors.Initialize(); this.DispatcherUnhandledException += App_DispatcherUnhandledException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; GalaSoft.MvvmLight.Threading.DispatcherHelper.UIDispatcher.BeginInvoke(new Action(() => { try { var trader = container.GetExportedValue <TraderModel>(); if (trader.IpPort > 0) { trader.IpPortActual = trader.IpPort; var protocol = trader.IpPort == 443 ? "https" : "http"; while (true) { string url = $"{protocol}://+:{trader.IpPortActual}/"; GalaSoft.MvvmLight.Messaging.Messenger.Default.Send(new LogMessage(new { trying = new { url } })); try { _webApp = WebApp.Start <StartUp>(url); GalaSoft.MvvmLight.Messaging.Messenger.Default.Send(new LogMessage(new { url })); break; } catch (Exception exc) { var he = exc.InnerException as System.Net.HttpListenerException; if (exc == null || he.ErrorCode != 183) { GalaSoft.MvvmLight.Messaging.Messenger.Default.Send(new LogMessage(new Exception(new { url } +"", exc))); return; } GalaSoft.MvvmLight.Messaging.Messenger.Default.Send(new LogMessage(new { port = trader.IpPortActual, isBusy = true } +"")); trader.IpPortActual++; if (trader.IpPortActual > trader.IpPort + 10) { GalaSoft.MvvmLight.Messaging.Messenger.Default.Send(new LogMessage(new { trader.IpPortActual, trader.IpPort, Limit = 10 })); return; } } } } } catch (CompositionException cex) { GalaSoft.MvvmLight.Messaging.Messenger.Default.Send <LogMessage>(new LogMessage(cex.ToJson())); AsyncMessageBox.BeginMessageBoxAsync(cex + ""); } catch (Exception exc) { AsyncMessageBox.BeginMessageBoxAsync(exc + ""); } }), System.Windows.Threading.DispatcherPriority.Background); }