© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
54 replies
FusedQyou

✅ How do I gracefully asynchronously exit a console application?

I am working on a console application that runs an asynchronous method until the console application exits. I want to gracefully exit this method and handle remaining work before fully closing.

The code currently looks like this (only relevant code shared)
Program.cs
Program.cs
: https://gdl.space/acabuvokev.cs
BotApplication.cs
BotApplication.cs
: https://gdl.space/tumeduveko.cs

Expected: The console logs
Stopped application.
Stopped application.
.
Actual: The last message was
Starting bot.
Starting bot.
.

Is this possible at all? I want to add additional logic below before the console is exited, but I can't figure out the correct way of doing this.
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

Console Application On Exit (Win 11)
C#CC# / help
2y ago
How do I use a API in a console application
C#CC# / help
8mo ago
is there a way to do Console.ReadLine() asynchronously?
C#CC# / help
3y ago
Prevent the exit button from closing console application
C#CC# / help
2y ago