Shortest way to write a thread-safe access method to a windows forms control

后端 未结 5 1023
北海茫月
北海茫月 2020-12-02 11:47

In this article:

http://msdn.microsoft.com/en-us/library/ms171728(VS.80).aspx

The author uses the following method to make thread-safe calls to a Windows For

5条回答
  •  自闭症患者
    2020-12-02 12:14

    The shortest solution I have found is shown in the button example below where the goal is to change the text of a button.

        if (buttonX.InvokeRequired)
            buttonX.Invoke((Action)(() => buttonX.Text = "Record"));
        else
            buttonX.Text = "Record";
    

提交回复
热议问题