Note that there are some explanatory texts on larger screens.

plurals
  1. POC# and Caliburn - RescueAttribute and Coroutines
    primarykey
    data
    text
    <p>I think I have found a situation where RescueAttribute is broken. Or maybe I am using co-routines incorrectly.</p> <p>I have a ViewModel like this:</p> <pre><code>[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(() =&gt; _server.Login()); //throw new Exception("Aww, snap!"); yield return Show.NotBusy(); } public void Rescue(Exception exc) { //Show a messagebox or something } } </code></pre> <p>AsyncResult is implemented like so:</p> <pre><code>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(() =&gt; Completed(this, new ResultCompletionEventArgs { Error = exc, WasCancelled = true })); return; } Exec.OnUIThread(() =&gt; Completed(this, new ResultCompletionEventArgs())); }); } public event EventHandler&lt;ResultCompletionEventArgs&gt; Completed = delegate { }; } </code></pre> <p>If I uncomment the exception in my above ViewModel, Rescue fails to handle the exception.</p> <p>Is this a bug in Caliburn, or is AsyncResult implemented wrong?</p> <p>If you put an exception before the yield to return an AsyncResult, Rescue works just fine. Also if the exception is thrown <em>on</em> the async thread, rescue still works!</p> <p>EDIT: you can also use Show.MessageBox instead of AsyncResult to reproduce the same problem.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload