BeginInvoke not invoking the target method in Release build
I have a method, which I wish to execute on the UI message pump and thus do the following:
private void SomeMethod() {
BeginInvoke(new MethodInvoker(MethodToInvoke));
}
private void MethodToInvoke() {
// This method contains code that I wish to execute on UI message pump.
}
Now, the above works just fine when I create a Debug build of the project. However, when I create a Release build, the "MethodToInvoke" method does not get invoked.
Does anyone have any idea why thi开发者_高级运维s might be?
Thanks, Elan
It turns out the call to BeginInvoke was throwing an exception, which I had missed. That of course explains why the target method was not getting executed.
System.InvalidOperationException: Invoke or BeginInvoke cannot be called on a control until the window handle has been created.
It's not clear however, why this exception was not thrown in the Debug build.
精彩评论