Note that there are some explanatory texts on larger screens.

plurals
  1. POBackgroundWorker capture error
    primarykey
    data
    text
    <p>I've been trying to follow this MSDN <a href="http://msdn.microsoft.com/en-us/library/cc221403%28v=vs.95%29.aspx" rel="nofollow noreferrer">example</a>, and using the code below. However, <code>e.Error</code> is ALWAYS null in RunWorkerCompleted even when an error does occur in SomeMethod();</p> <pre><code>private void WorkerDoWork(object sender, DoWorkEventArgs e) { getMethod = SomeMethod(); } private void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Error != null) { var result = ModernDialog.ShowMessage("Error occurred.... " + e.Result, "ErrorTitle", MessageBoxButton.OK); } else if (e.Cancelled) { } Else { } } </code></pre> <p>Can anyone see what I'm doing wrong?</p> <p>I can get around it by doing the following but I don't really understand why the example in MSDN is not working for me?</p> <pre><code>private void WorkerDoWork(object sender, DoWorkEventArgs e) { try { getMethod = SomeMethod(); } catch(Exception ex) { e.Result = ex; } } private void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Result is Exception) { var result = ModernDialog.ShowMessage("Error occurred.... " + e.Result, "ErrorTitle", MessageBoxButton.OK); } //etc } </code></pre> <p>Also, using the second method I can't access the .Message from e.Result. For example, in WorkerDoWork I can use <code>ex.Message</code></p> <p>Edit: I've setup the worker to create it's own error and I still get e.Error == null. The variable displayed is a bit faint as CTRL+PrtSc makes it fade <img src="https://i.stack.imgur.com/m85GI.png" alt="enter image description here"></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.
 

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