© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
71 replies
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...");
        };
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...");
        };
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

✅ telling a console app to exit
C#CC# / help
3y ago
✅ How do I gracefully asynchronously exit a console application?
C#CC# / help
2y ago
❔ how do i use discord webhooks in a console app?
C#CC# / help
3y ago