/// <summary> /// Starts HTTP services /// </summary> public async Task Start() { _httpListener.Start(); var requests = new HashSet <Task>(); for (int i = 0; i < MaxConcurrentRequests; i++) { requests.Add(_httpListener.GetContextAsync()); } while (!_tokenSource.Token.IsCancellationRequested) { Task t = await Task.WhenAny(requests); requests.Remove(t); if (t is Task <HttpListenerContext> ) { var context = (t as Task <HttpListenerContext>).Result; requests.Add(ProcessRequestAsync(context)); requests.Add(_httpListener.GetContextAsync()); } else { if (t.IsFaulted) { OnUnhandledException?.Invoke(t.Exception); } } } }
public void Start(params string[] args) { var messagePublisherFactory = _configurer.Resolve <IMessagePublisherFactory>(); Task.Run(() => { var publishConfirmTimeOut = TimeSpan.FromSeconds(3); using (var messagePublisher = messagePublisherFactory.Create("myExchange0")) { var confirmed = messagePublisher .Publish("myMessage", new TestMessage("Testing sending a message using RabbitMQ")) .WaitForConfirm(publishConfirmTimeOut, out var timedOut); if (confirmed == false) { throw new InvalidOperationException("Failed waiting for publish confirm."); } if (timedOut) { throw new TimeoutException($"Timed out waiting for confirms. Waited for {publishConfirmTimeOut.TotalSeconds}s."); } messagePublisher .Publish("messageConfirmed", new TestMessage("Test message has been confirmed")); } }).ContinueWith(task => { OnUnhandledException?.Invoke(task.Exception); }, TaskContinuationOptions.OnlyOnFaulted); }
public void Update(DateTime now) { Now = now; while (queue.Count > 0) { var timer = queue.Top; if (timer.IsStopped) { queue.Dequeue(); continue; } if (timer.At > Now) { break; } var callback = timer.Callback; timer.Stop(); queue.Dequeue(); try { callback?.Invoke(); } catch (Exception e) { OnUnhandledException?.Invoke(e); } } }
public int Start(params string[] args) { Task.Run(() => _app.Start(args)) .ContinueWith(task => OnUnhandledException?.Invoke(task.Exception), TaskContinuationOptions.OnlyOnFaulted); return(0); }
public void Start(params string[] args) { var threads = int.Parse(args.First()); var messageConsumerFactory = _configurer.Resolve <IMessageConsumerFactory>(); var messagePublisherFactory = _configurer.Resolve <IMessagePublisherFactory>(); Task.Run(() => { Parallel.For(0, threads, i => { _messageConsumers.Add(messageConsumerFactory.Consume <TestMessage>( "myExchange" + i % 2, "queue" + i % 2, "routing" + i % 2, message => { using (var messagePublisher = messagePublisherFactory.Create("myExchange" + i % 2)) { messagePublisher.Publish("myMessage", new TestMessage(i + ": " + message.Message)); } })); }); }).ContinueWith(task => { OnUnhandledException?.Invoke(task.Exception); }, TaskContinuationOptions.OnlyOnFaulted); }
public ApplicationWrapper(IApplication app) { _app = app; app.OnUnhandledException += exception => { OnUnhandledException?.Invoke(exception); }; }
private static void CaptureUnhandledException(object sender, UnhandledExceptionEventArgs arg) { OnUnhandledException?.Invoke(sender, arg); Logger.Fatal( $"Unhandled Mono Exception Thrown '{arg.ExceptionObject.GetType().Name}':\n───────────────\n{arg.ExceptionObject}\n───────────────"); if (arg.IsTerminating) { Logger.Fatal("Exception Terminating"); } }
public void Start(params string[] args) { Task.Run(() => { var connectionFactory = _configurer.Resolve <IConnectionFactory>(); _connection = connectionFactory.CreateConnection(); }).ContinueWith(task => { OnUnhandledException?.Invoke(task.Exception); }, TaskContinuationOptions.OnlyOnFaulted); }
public Task <int> StartAsync(CancellationToken cancellationToken = default, params string[] args) { try { var startCode = _app.Start(args); return(Task.FromResult(startCode)); } catch (Exception exception) { OnUnhandledException?.Invoke(exception); return(Task.FromResult(-1)); } }
private void Unwind() { Contract.Requires(CurrentException != null); for (var frame = CurrentFrame; frame != null; frame = frame.Caller) { if (frame.TryHandle(CurrentException)) { CurrentFrame = frame; return; } } OnUnhandledException?.Invoke(CurrentException); throw new UnhandledExceptionException(CurrentException.ThrownValue.CastToString()); }
public void Start(params string[] args) { var messagesToPublish = int.Parse(args.First()); var messagePublisherFactory = _configurer.Resolve <IMessagePublisherFactory>(); Task.Run(() => { Parallel.For(0, messagesToPublish, i => { using (var messagePublisher = messagePublisherFactory.Create("myExchange" + i % 2)) { messagePublisher.Publish("myMessage", new TestMessage("Testing sending a message using RabbitMQ")); } }); }).ContinueWith(task => { OnUnhandledException?.Invoke(task.Exception); }, TaskContinuationOptions.OnlyOnFaulted); }
public int Start(params string[] args) { var startCode = (int)HostFactory.Run(config => { using (config.UseApplicationHostBuilder(args)) { config.OnException(exception => OnUnhandledException?.Invoke(exception)); config.Service <TService>(settings => { settings.ConstructUsing(hostSettings => _service); settings.WhenStarted((service, control) => { _control = control; var code = service.Start(); return(code == 0); }); settings.WhenStopped(service => { service.Stop(); }); }); } }); return(startCode); }
private async Task ProcessItemAsync(QueueItem <TItem> queueItem, CancellationToken cancellationToken) { var holderId = queueItem.HolderId; try { var processed = await _ProcessItemFunc(queueItem.Value, cancellationToken).ConfigureAwait(false); if (processed) { await _ItemQueue.RemoveQueueItemAsync(queueItem.Id, holderId, cancellationToken).ConfigureAwait(false); return; } await Task.Delay(_ItemQueueProcessorSettings.ItemRetryDelay, cancellationToken).ConfigureAwait(false); await _ItemQueue.ReleaseQueueItemAsync(queueItem.Id, holderId, cancellationToken).ConfigureAwait(false); } catch (Exception e) { OnUnhandledException?.Invoke(queueItem.Value, e); } }
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { OnUnhandledException?.Invoke(); }
public TopshelfHostService(TService service) { _service = service; _service.OnUnhandledException += exception => OnUnhandledException?.Invoke(exception); }
public void Handle(Exception e) { OnUnhandledException?.Invoke(this, e); }