Good opinion IMHO, another SO answer is actually not the way for window forms, although it may be wrong.
Usually you use ISynchronizeInvoke for such a function in WinForms. Each container control implements this interface.
You will need the BeginInvoke() method to transfer the call back to the appropriate stream.
For your previous question, the code would look like this:
public class SomeObject : INotifyPropertyChanged { private readonly ISynchronizeInvoke invoker; public SomeObject(ISynchronizeInvoke invoker) { this.invoker = invoker; } public decimal AlertLevel { get { return alertLevel; } set { if (alertLevel == value) return; alertLevel = value; OnPropertyChanged("AlertLevel"); } } private void OnPropertyChanged(string propertyName) { if (PropertyChanged != null) { this.invoker.BeginInvoke((Action)(() => PropertyChanged(this, new PropertyChangedEventArgs(propertyName))), null); } } }
Where you pass your own Form class to the SomeObject constructor. PropertyChanged will now be added to the custom form class UI thread.
Ric .Net
source share