Solve a cross-threading Exception in WinForms

后端 未结 6 1793
北荒
北荒 2020-12-01 17:14

Presently I\'m working with WinForms(in C#) and I have to run the application in the background. For this purpose I\'m using asynchronous. When I run the application it\'s s

6条回答
  •  死守一世寂寞
    2020-12-01 17:46

    The UI changes can be done with Control.Invoke() methods, this cross thread exception can be solved using below code snippet.

    void UpdateWorker()
    {
       //Here ddUser is the user control
       //Action to be performed should be called within { } as like below code
       if (this.ddUser.InvokeRequired)
          ddUser.Invoke(new MethodInvoker(() => { ddUser.Size = new Size(100, 100); }));
    }
    

提交回复
热议问题