Β© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#β€’16mo agoβ€’
55 replies
Moonlit πŸ‘‘πŸΆ

Can I catch an error from Task.Run to stop threads crashing main program?

I have a bot that is meant to support multiple platforms like (Twitch, Discord, Spotify, Etc). I do this by loading them all as .DLL files. I've tried my hardest to make sure that any errors in commands from modules doesn't crash the bot, but the issue is that if the Task Initializing has an error, it would cause the main program to crash because the Try/Catch that starts it doesn't work because it's on a separate thread I assume?

Anyway I know I could catch an error in each modules Initializing method to prevent this and to end the task gracefully, but I'd like to make the bot impervious to being crashes by any modules. I don't want to rely on the modules themselves to do it.

Is that possible? If so then how?

PS: Line 46 is where I do it and ignore
// RunCommand not accessible
// RunCommand not accessible
I fixed that.
Screenshot_2024-10-22_201847.png
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

I want to check the program test.exe stops, can't run the main program.
C#CC# / help
3y ago
βœ… Run code in main thread after Task.Run completed?
C#CC# / help
3y ago
How to use use ReadKey in a Task when i'm using ReadKey elsewhere to stop the program from exiting?
C#CC# / help
4y ago
βœ… My program can’t be run.
C#CC# / help
16mo ago