What's the difference between Invoke() and BeginInvoke()

前端 未结 6 1839
无人共我
无人共我 2020-11-22 01:14

Just wondering what the difference between BeginInvoke() and Invoke() are?

Mainly what each one would be used for.

EDIT: What is t

6条回答
  •  再見小時候
    2020-11-22 01:56

    The difference between Control.Invoke() and Control.BeginInvoke() is,

    • BeginInvoke() will schedule the asynchronous action on the GUI thread. When the asynchronous action is scheduled, your code continues. Some time later (you don't know exactly when) your asynchronous action will be executed
    • Invoke() will execute your asynchronous action (on the GUI thread) and wait until your action has completed.

    A logical conclusion is that a delegate you pass to Invoke() can have out-parameters or a return-value, while a delegate you pass to BeginInvoke() cannot (you have to use EndInvoke to retrieve the results).

提交回复
热议问题