C#C
C#3y ago
Tiger

❔ how do delay the process exit for a graceful shutdown in a console app?

Hey, I want to delay the app exit by a few seconds, I tried using the following but it's just exiting instantaneously
AppDomain.CurrentDomain.ProcessExit += delegate(object sender, EventArgs eventArgs)
        {
            GlobalState.CancellationRequested = true;
            LogService.EzLogger.LogInfoAsync("[PROCESSOR] Shutting down gracefully", null);
            Console.WriteLine("Shutting down...");  
            Thread.Sleep(TimeSpan.FromSeconds(30));
            Console.WriteLine("Finished shutting down...");
        };
Was this page helpful?