Using C# MethodInvoker.Invoke() for a GUI app… is this good?

前端 未结 5 1779
死守一世寂寞
死守一世寂寞 2020-12-01 01:01

Using C# 2.0 and the MethodInvoker delegate, I have a GUI application receiving some event from either the GUI thread or from a worker thread.

I use the following pa

5条回答
  •  情歌与酒
    2020-12-01 01:27

    The method.Invoke() call executes the delegate on the current executing thread. Using the BeginInvoke(method) ensures that the delegate is called on the GUI thread.

    This is the correct way of avoiding code duplication when the same method can be called both from the GUI thread and other threads.

提交回复
热议问题