Automating the InvokeRequired code pattern

后端 未结 9 1309
醉话见心
醉话见心 2020-11-21 23:57

I have become painfully aware of just how often one needs to write the following code pattern in event-driven GUI code, where

private void DoGUISwitch() {
           


        
9条回答
  •  萌比男神i
    2020-11-22 00:19

    Here's the form I've been using in all my code.

    private void DoGUISwitch()
    { 
        Invoke( ( MethodInvoker ) delegate {
            object1.Visible = true;
            object2.Visible = false;
        });
    } 
    

    I've based this on the blog entry here. I have not had this approach fail me, so I see no reason to complicate my code with a check of the InvokeRequired property.

    Hope this helps.

提交回复
热议问题