private void GoHangfireServer() { var o = this.ServiceProvider.GetService <IOptions <HangfireServerConfig> >().Value; var logger = this.ServiceProvider.GetService <ILogger>(); GlobalConfiguration.Configuration.UseSqlServerStorage(Configuration.GetConnectionString(o.ConnectionStringName)); GlobalConfiguration.Configuration.UseActivator(new MyActivator(this)); GlobalJobFilters.Filters.Add(new TraffkJobFilterAttribute(Configuration)); var bo = o.BackgroundOptions ?? new BackgroundJobServerOptions(); var queues = new List <string>(); queues.AddRange(bo.Queues.Where(q => !q.StartsWith("-")).ToArray()); bo.Queues.Where(q => q.StartsWith("-")).ForEach(q => queues.Remove(q.Substring(1))); bo.Queues = queues.ToArray(); OnHangfireServerInitialized(); using (var s = new BackgroundJobServer(bo)) { var timeout = Parse.ParseTimeSpan(Configuration["JobRunner:TimeOut"], TimeSpan.FromSeconds(60)); do { logger.Information("Job Runner Heartbeat."); }while (!ShutdownRequested.WaitOne(timeout)); } }
public async Task StartAsync() { var listener = new TcpListener(IPAddress.Loopback, 8081); listener.Start(); var client = await listener.AcceptTcpClientAsync(); client.Close(); listener.Stop(); ShutdownRequested?.Invoke(this, new EventArgs()); }
public void Handle(ShutdownRequested message) { //TODO: ask all the loaded modules if they have unsaved information and prompt the user for confirmation or cancelling if they do. if (false) { message.Cancelled = true; } else { MessageBus.Publish(new Shutdown()); } }
private bool DoShutdown(ShutdownRequestedEventArgs e, bool force = false, int exitCode = 0) { if (!force) { ShutdownRequested?.Invoke(this, e); if (e.Cancel) { return(false); } if (_isShuttingDown) { throw new InvalidOperationException("Application is already shutting down."); } } _exitCode = exitCode; _isShuttingDown = true; try { // When an OS shutdown request is received, try to close all non-owned windows. Windows can cancel // shutdown by setting e.Cancel = true in the Closing event. Owned windows will be shutdown by their // owners. foreach (var w in Windows) { if (w.Owner is null) { w.Close(); } } if (!force && Windows.Count > 0) { e.Cancel = true; return(false); } var args = new ControlledApplicationLifetimeExitEventArgs(exitCode); Exit?.Invoke(this, args); _exitCode = args.ApplicationExitCode; } finally { _cts?.Cancel(); _cts = null; _isShuttingDown = false; } return(true); }
private void ProcessMessage(string message, IPAddress server) { if (!message.StartsWith(MessageShutdown)) { return; } var cluster = message.Split('|')[1]; ShutdownRequested?.Invoke(this, new ShutdownRequestedEventArgs { Address = server, Cluster = cluster }); }
private void MainWindow_Closing(object sender, CancelEventArgs e) { //If this was the result of the user requesting the close, we'll publish the message and see if anyone cancelled it. if (!GlobalApplicationState.ShuttingDown) { ShutdownRequested shutdownRequested = new ShutdownRequested(); GlobalApplicationState.MessageBus.Publish(shutdownRequested); if (shutdownRequested.Cancelled) { e.Cancel = true; } } }
protected override Response OnReceive(SimpleMessagePurport message) { switch (message) { case SimpleMessagePurport.ClientIsReady: ClientReady?.Invoke(); return(new SimpleResponse(SimpleResponsePurport.Acknowledged)); case SimpleMessagePurport.ConfigurationNeeded: return(HandleConfigurationRequest()); case SimpleMessagePurport.RequestShutdown: ShutdownRequested?.Invoke(); return(new SimpleResponse(SimpleResponsePurport.Acknowledged)); } return(new SimpleResponse(SimpleResponsePurport.UnknownMessage)); }
private void ActualInteractHandler(IntPtr smcConn) { var e = new ShutdownRequestedEventArgs(); if (_platform.Options?.EnableSessionManagement ?? false) { ShutdownRequested?.Invoke(this, e); } SMLib.SmcInteractDone(smcConn, e.Cancel); if (e.Cancel) { return; } _saveYourselfPhase = false; SMLib.SmcSaveYourselfDone(smcConn, true); }
private void OnShutdownRequested(object sender, ShutdownRequestedEventArgs e) { ShutdownRequested?.Invoke(this, e); if (e.Cancel) { return; } // When an OS shutdown request is received, try to close all non-owned windows. Windows can cancel // shutdown by setting e.Cancel = true in the Closing event. Owned windows will be shutdown by their // owners. foreach (var w in Windows) { if (w.Owner is null) { w.Close(); } } if (Windows.Count > 0) { e.Cancel = true; } }
private void ShutDownRequsted() { ShutdownRequested?.Invoke(this, EventArgs.Empty); }
private static void OnShutdownRequested() { ShutdownRequested?.Invoke(null, EventArgs.Empty); }
protected void OnShutdownRequested(bool force) { ShutdownRequested?.Invoke(this, force); }