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); }
public void RX_Action2() { var yp = DataFlowProcessors.CreateYieldingTargetBlock <int>(i => { Debug.WriteLine("ab:" + i); Thread.Sleep(1000); if (i.Between(500, 700)) { throw new MulticastNotSupportedException(); } }, exc => { Debug.WriteLine(exc); }); Enumerable.Range(0, 1000).ToList().ForEach(i => { yp.Post(i); //Debug.WriteLine("ss:" + i); Thread.Sleep(10); }); Debug.WriteLine("Waiting for ab."); Thread.Sleep(5000); }