开发者

BeginInvoke not invoking the target method in Release build

开发者 https://www.devze.com 2023-01-03 06:02 出处:网络
I have a method, which I wish to execute on the UI message pump and thus do the following: private void SomeMethod() {

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消