What happens to an abandoned Task with an exception
I have a scenario where I start a Task to fetch some data from an external source, but if it doesn't complete within a set amount of time I ignore it and return a View to the client.
Ie this is happening inside an MVC controller, I start the Task, but if it hasn't completed within 2 seconds I simply continue and never use it's results.
However I'm now wondering how/if I should handle exceptions that might happen within the Task after the 2 seconds have passed - I'm not cancelling the Task because I want to cache the data when it eventually arrives, and I'm not swallowing the exception at any point because I want it to propagate up to the controller if it occurs within those 2 seconds.
Basically I'm worried that the exception might cause some unforeseen problems if not handled properly if it occurs after I've already returned from the controller method that started it.
EDIT: For more clarification, my controller method starts up a Task, but doesn't wait for it to complete. It returns a View, and the Task keeps running to completion. The Task calls an external WS which might return an exception. It's generally handled by the controller method, but in some cases (when Task takes >2 seconds) the controller method has already been returned from, and the Tasks exception never gets explicitly handled
0 comments:
Post a Comment