Windows Form UI and Thread Safety on Controls
-
Hello All, I'm working on a project where I'll have multiple controls on a Windows form that may get updated when messages are received on a socket being listened on by a worker thread or the controls might get updated from the main thread. The way I currently understand it is I need to set the controls properties using a delagate if control.InvokeRequired is true. How could this be done without having to have a delagate method for each control on the form? There are many of them and they all could be updated from the worker thread. All advice is appreciated. Thanks.
-
Hello All, I'm working on a project where I'll have multiple controls on a Windows form that may get updated when messages are received on a socket being listened on by a worker thread or the controls might get updated from the main thread. The way I currently understand it is I need to set the controls properties using a delagate if control.InvokeRequired is true. How could this be done without having to have a delagate method for each control on the form? There are many of them and they all could be updated from the worker thread. All advice is appreciated. Thanks.
Try reading up on the SynchronizationContext class. This article[^] might be a good start.