This turned out to be a pure implementation (relatively). It was just necessary to include a link to WindowsBase.dll , which, it turns out, will be the WPF library, so ... I did not really like it, but this solution ...:
public class GUIThreadDispatcher { private static volatile GUIThreadDispatcher itsSingleton; private Dispatcher itsDispatcher; private GUIThreadDispatcher() { } public static GUIThreadDispatcher Instance { get { if (itsSingleton == null) itsSingleton = new GUIThreadDispatcher(); return itsSingleton; } } public void Init() { itsDispatcher = Dispatcher.CurrentDispatcher; } public object Invoke(Action method, DispatcherPriority priority = DispatcherPriority.Render, params object[] args) { return itsDispatcher.Invoke(method, priority, args); } public DispatcherOperation BeginInvoke(Action method, DispatcherPriority priority = DispatcherPriority.Render, params object[] args) { return itsDispatcher.BeginInvoke(method, priority, args); }
Then initialize it as follows:
static class Program {
And then use it like this:
public class SomeObject: INotifyPropertyChanged { public decimal AlertLevel { get { return alertLevel; } set { if(alertLevel == value) return; alertLevel = value; OnPropertyChanged("AlertLevel"); } private void OnPropertyChanged(string propertyName) { GUIThreadDispatcher.Instance.BeginInvoke(() => { if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); }); }}
Denis
source share