Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. I need to wait till the Invoke finish its work, and then continue the method. 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    
}
like image 968
ContentPenalty Avatar asked Sep 19 '14 15:09

ContentPenalty


1 Answers

You don't need to do anything. Invoke (unlike BeginInvoke) will block until the scheduled delegate has finished executing.

like image 165
Servy Avatar answered Oct 15 '22 15:10

Servy