public static void Start(this PropertyChangedEventHandler?Handler, object Sender, params string[] PropertyName) { if (PropertyName is null) { throw new ArgumentNullException(nameof(PropertyName)); } if (Handler is null || PropertyName.Length == 0) { return; } var args = PropertyName.ToArray(name => new PropertyChangedEventArgs(name)); foreach (var d in Handler.GetInvocationList()) { switch (d.Target) { case ISynchronizeInvoke { InvokeRequired: true } synchronize_invoke: foreach (var arg in args) { synchronize_invoke.Invoke(d, new[] { Sender, arg }); } break; default: foreach (var arg in args) { d.DynamicInvoke(Sender, arg); } break; } } }
public static void ThreadSafeInvoke( this PropertyChangedEventHandler?Event, object?sender, [NotNull, ItemCanBeNull] params string[] PropertyName) { if (PropertyName is null) { throw new ArgumentNullException(nameof(PropertyName)); } if (Event is null || PropertyName.Length == 0) { return; } var args = PropertyName.ToArray(name => new PropertyChangedEventArgs(name)); foreach (var d in Event.GetInvocationList()) { switch (d.Target) { case ISynchronizeInvoke { InvokeRequired: true } synchronize_invoke: foreach (var arg in args) { synchronize_invoke.Invoke(d, new[] { sender, arg }); } break; case DispatcherObject dispatcher_obj when !dispatcher_obj.CheckAccess(): foreach (var arg in args) { dispatcher_obj.Dispatcher.Invoke(d, arg); } break; default: foreach (var arg in args) { d.DynamicInvoke(sender, arg); } break; } } }