Control.EndInvoke resets call stack for exception

Posted by Brian Rasmussen on Stack Overflow See other posts from Stack Overflow or by Brian Rasmussen
Published on 2010-04-12T11:59:13Z Indexed on 2010/04/12 12:03 UTC
Read the original article Hit count: 399

Filed under:
|
|
|

I don't do a lot of Windows GUI programming, so this may all be common knowledge to people more familiar with WinForms than I am. Unfortunately I have not been able to find any resources to explain the issue, I encountered today during debugging.

If we call EndInvoke on an async delegate. We will get any exception thrown during execution of the method re-thrown. The call stack will reflect the original source of the exception.

However, if we do something similar on a Windows.Forms.Control, the implementation of Control.EndInvoke resets the call stack. This can be observed by a simple test or by looking at the code in Reflector. The relevant code excerpt from EndInvoke is here:

if (entry.exception != null)
{
   throw entry.exception;
}

I understand that Begin/EndInvoke on Control and async delegates are different, but I would have expected similar behavior on Control.EndInvoke.

Is there any reason Control doesn't do whatever it is async delegates do to preserve the original call stack?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about exception