Action methods returning Task and exception handling
See original GitHub issueHi!
First of all, big thanks for this amazing library. I have just started using it and I really enjoy working with it, it’s great!
One thing I love about Stylet is the Command="{stylet:Action Execute}"
command binding. I also found it surprising (in a good way) that it handles async
methods that return Task
.
However, there is a little caveat, that is if the Task is not awaited or disposed, any exceptions it generates will be uncaught.
This leads to problems:
- Exceptions are not caught so methods may silently fail to execute.
- The whole application will crash after an arbitrary time when GC finalizes the task, causing an unhandled exception.
I haven’t had the chance to look at the code yet, but I suppose it’s impossible to await tasks in the code that handles execution of actions in Stylet.
One alternative solution would be trailing tasks with .ContinueWith()
that will dispose the task on the Dispatcher thread, thus forcing the exception to be shown to the user and instantly close the application.
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (7 by maintainers)
Top GitHub Comments
Also wanted to add - great library, I’m using it for a few weeks now and I’m thoroughly impressed!
Ok good points!