简体   繁体   English

C#等待MethodInvoker完成

[英]C# wait for MethodInvoker to finish

I need to accomplish the following scenario. 我需要完成以下场景。 ThreadMethod() is a Timer method, where I have UI update in the Invoke statement. ThreadMethod()是一个Timer方法,我在Invoke语句中有UI更新。 I need to wait till the Invoke finish its work, and then continue the method. 我需要等到Invoke完成它的工作,然后继续该方法。 How can I cope with this? 我怎么能应付这个?

public void ThreadMethod(){
//do some work

            this.Invoke((MethodInvoker)delegate
            {
            //do some GUI update
            });

//wait till Invoke finish its work    
}

You don't need to do anything. 你不需要做任何事情。 Invoke (unlike BeginInvoke ) will block until the scheduled delegate has finished executing. Invoke (与BeginInvoke不同)将阻塞,直到调度的委托完成执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM