C # and Caliburn - RescueAttribute and Corouts

I think I found a situation where the RescueAttribute is broken. Or maybe I'm misusing soklokalnye procedures.

I have a ViewModel like this:

[Rescue("Rescue")] class MyViewModel { //... left out some bus-logic code here ... public void Login() { yield return Show.Busy(); //the following line will also cause the problem, just like AsyncResult //yield return Show.MessageBox("Test"); yield return new AsyncResult(() => _server.Login()); //throw new Exception("Aww, snap!"); yield return Show.NotBusy(); } public void Rescue(Exception exc) { //Show a messagebox or something } } 

AsyncResult is implemented as follows:

 using Exec = Caliburn.PresentationFramework.Invocation.Execute; public class AsyncResult : IResult { private readonly Action _function; public AsyncResult(Action function) { _function = function; } public void Execute(ResultExecutionContext context) { Exec.OnBackgroundThread(delegate { try { _function(); } catch (Exception exc) { Exec.OnUIThread(() => Completed(this, new ResultCompletionEventArgs { Error = exc, WasCancelled = true })); return; } Exec.OnUIThread(() => Completed(this, new ResultCompletionEventArgs())); }); } public event EventHandler<ResultCompletionEventArgs> Completed = delegate { }; } 

If I uncomment the exception in my ViewModel above, Rescue will not be able to handle the exception.

Is this a bug in Caliburn, or is AsyncResult implemented incorrectly?

If you throw an exception before exiting to return AsyncResult, Rescue works fine. Also, if an exception is thrown in an asynchronous stream, recovery still works!

EDIT: You can also use Show.MessageBox instead of AsyncResult to reproduce the same issue.

+4
source share
2 answers

This seems like a legal mistake. I added a problem for this in the Caliburn tracker: http://caliburn.codeplex.com/workitem/7636

EDIT: The problem has been fixed.
see http://caliburn.codeplex.com/Thread/View.aspx?ThreadId=234229

+3
source

I suggested changing the IDispatcher that might apply to this problem:

http://caliburn.codeplex.com/Thread/View.aspx?ThreadId=223873

0
source

All Articles