C#C
C#2y ago
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: https://gdl.space/acabuvokev.cs
BotApplication.cs: https://gdl.space/tumeduveko.cs

Expected: The console logs Stopped application..
Actual: The last message was 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.
Was this page helpful?