Improved cross threaded invocation.

This commit is contained in:
Michael Bucari-Tovo 2021-08-13 16:34:09 -06:00
parent 766d427b19
commit a44c46333f
5 changed files with 149 additions and 55 deletions

View file

@ -4,15 +4,13 @@ using System.Threading;
namespace LibationWinForms
{
public abstract class AsyncNotifyPropertyChanged : INotifyPropertyChanged
public abstract class AsyncNotifyPropertyChanged : SynchronizeInvoker, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private CrossThreadSync<PropertyChangedEventArgs> ThreadSync { get; } = new CrossThreadSync<PropertyChangedEventArgs>();
public AsyncNotifyPropertyChanged()
=>ThreadSync.ObjectReceived += (_, args) => PropertyChanged?.Invoke(this, args);
public AsyncNotifyPropertyChanged() { }
protected void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
=> ThreadSync.Post(new PropertyChangedEventArgs(propertyName));
=>BeginInvoke(PropertyChanged, new object[] { this, new PropertyChangedEventArgs(propertyName) });
}
}