Comments (2)
After some investigation, I found this event handler to do the trick:
AppDomain.CurrentDomain.UnhandledException
I'm not sure if this handler catches all exceptions, or if we need to use TaskManager.UnobservedTaskException
as well.
from fluentscheduler.
When you () => { }
the library creates a thread and calls your action on it. If any exception is raised the library is able to catch it and tell you on UnobservedTaskException
.
When you async () => { }
the library creates a thread that then calls your action which, for being asynchronous, spawns another thread. Since the library don't await
your action (it just calls it), the unhandled exception in this second thread crashes the application and you're only able to get a last glance at it on UnhandledException
of AppDomain
before everything falls down.
Here's a little illustration of what's going on:
static async Task Boom()
{
throw new Exception("BOOOM!");
}
static void Main(string[] args)
{
// Bye-bye message
AppDomain.CurrentDomain.UnhandledException += (sender, e) => Console.WriteLine("Aww, we crashed...");
Action synchronous = () => Boom().Wait();
Action asynchronous = async () => await Boom();
// This one prints "Gotcha!"
try { synchronous(); }
catch { Console.WriteLine("Gotcha!"); }
// This one doesn't print "Gotcha!" and crashes the application
try { asynchronous(); }
catch { Console.WriteLine("Gotcha!"); }
Thread.Sleep(Timeout.Infinite);
}
But don't worry, fixing your example is rather simple:
Schedule(() => {
var faulty= new FaultyComponent().Run(); // Here the faulty task starts to run on its own thread
// Do some other stuff
faulty.Wait(); // Here we join back the faulty task, if any exception were raised you're gonna get it wrapped in an AggregateException
}).ToRunOnceIn(1).Seconds();
from fluentscheduler.
Related Issues (20)
- run all other jobs after one job is done HOT 1
- Provide a dashboard HOT 2
- API suggestion Add ToCronExp to ITimeCalculator in version-6 HOT 1
- Version-6 add AllowReentrant config support
- Schedule a job to run every day at specific time?
- How to schedule a one-off event at run-time? HOT 2
- How to cancel a job automatically if it's not completed in a certain amount of time?
- How to use in work service (.net core 5.0)
- Question about scheduling with DateTime
- [MacOs] Cannot schedule job to run after x minutes if machine sleeps. HOT 2
- Why hasn't it been updated for 2 years HOT 1
- NextRun does sometimes not get updated or updated incorrectly HOT 3
- [Version 6.0] Hours, Minutes and Seconds not returning RestrictionUnit
- [Feature] Schedule next run (execution) inside Execute method
- is performance tested?
- Question I have about scheduling. HOT 1
- Feature Request: Retry on Error HOT 1
- [Bug] Accuracy problem HOT 1
- We need someone new to maintain this library HOT 6
- RobiniaDocs API Explorer
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fluentscheduler.