Help needed for 'cross-thread operation error' in C#

后端 未结 6 2017
野的像风
野的像风 2021-01-16 03:34

In the following code MessageReceived is on a different thread to label1 and when trying to access it I will get this error:

6条回答
  •  别那么骄傲
    2021-01-16 04:17

    Hopefully this will be closed as an exact duplicate, but if not:

    Don't touch the GUI from a non-GUI thread. Use BackgroundWorker and report progress appropriately, or read the WinForms page of my threading article for more direct control (Control.Invoke/BeginInvoke).

提交回复
热议问题