views:

20

answers:

1

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 this might be?

Thanks, Elan

+1  A: 

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.

Elan
It could be a timing issue. In the debugger other stuff is going on which could give your window handle time to be created.
ChrisF