EventHandlerExtensions

Name Value
Assembly Catel.Core
Namespace Catel
Available on .NET Framework 4.5, .NET Framework 4.6, Portable Class Libraries, Xamarin - Android, Xamarin - iOS
public static class EventHandlerExtensions

Extensions for event handlers.

Methods

SafeInvoke(EventHandler handler, object sender)

Invokes the specified handler in a thread-safe manner with as parameter for the event args. Where normally one has to write the following code:``` var handler = MyEvent; if (handler != null) { handler(this, EventArgs.Empty); }

MyEvent.SafeInvoke(this);
    

Parameters

Name Description
handler The handler.
sender The sender.

Returns

true if the event handler was notnull; otherwisefalse.

SafeInvoke(EventHandler handler, object sender, EventArgs e)

Invokes the specified handler in a thread-safe manner with as parameter for the event args. Where normally one has to write the following code:``` var handler = MyEvent; if (handler != null) { handler(this, EventArgs.Empty); }

MyEvent.SafeInvoke(this);
    

Parameters

Name Description
handler The handler.
sender The sender.
e The event args.

Returns

true if the event handler was notnull; otherwisefalse.

SafeInvoke(EventHandler<EventArgs> handler, object sender)

Invokes the specified handler in a thread-safe manner with as parameter for the event args. Where normally one has to write the following code:``` var handler = MyEvent; if (handler != null) { handler(this, EventArgs.Empty); }

MyEvent.SafeInvoke(this);
    

Parameters

Name Description
handler The handler.
sender The sender.

Returns

true if the event handler was notnull; otherwisefalse.

SafeInvoke(NotifyCollectionChangedEventHandler handler, object sender, Func<NotifyCollectionChangedEventArgs> fE)

Invokes the specified handler in a thread-safe manner. Where normally one has to write the following code:``` var handler = CollectionChanged; if (handler != null) { handler(this, e, new NotifyCollectionChangedEventArgs(…)); }

CollectionChanged.SafeInvoke(this, e, new NotifyCollectionChangedEventArgs(...));
    

Parameters

Name Description
handler The handler.
sender The sender.
fE The event args.

Returns

true if the event handler was notnull; otherwisefalse.

SafeInvoke(NotifyCollectionChangedEventHandler handler, object sender, NotifyCollectionChangedEventArgs e)

Invokes the specified handler in a thread-safe manner. Where normally one has to write the following code:``` var handler = CollectionChanged; if (handler != null) { handler(this, e, new NotifyCollectionChangedEventArgs(…)); }

CollectionChanged.SafeInvoke(this, e, new NotifyCollectionChangedEventArgs(...));
    

Parameters

Name Description
handler The handler.
sender The sender.
e The event args.

Returns

true if the event handler was notnull; otherwisefalse.

SafeInvoke(PropertyChangedEventHandler handler, object sender, Func<PropertyChangedEventArgs> fE)

Invokes the specified handler in a thread-safe manner. Where normally one has to write the following code:``` var handler = PropertyChanged; if (handler != null) { handler(this, e, new PropertyChangedEventArgs(“propertyName”)); }

PropertyChanged.SafeInvoke(this, e, new PropertyChangedEventArgs("propertyName"));
    

Parameters

Name Description
handler The handler.
sender The sender.
fE The event args.

Returns

true if the event handler was notnull; otherwisefalse.

SafeInvoke(PropertyChangedEventHandler handler, object sender, PropertyChangedEventArgs e)

Invokes the specified handler in a thread-safe manner. Where normally one has to write the following code:``` var handler = PropertyChanged; if (handler != null) { handler(this, e, new PropertyChangedEventArgs(“propertyName”)); }

PropertyChanged.SafeInvoke(this, e, new PropertyChangedEventArgs("propertyName"));
    

Parameters

Name Description
handler The handler.
sender The sender.
e The event args.

Returns

true if the event handler was notnull; otherwisefalse.

SafeInvoke<TEventArgs>(EventHandler<TEventArgs> handler, object sender, Func<TEventArgs> fE)

Invokes the specified handler in a thread-safe manner. Where normally one has to write the following code:``` var handler = MyEvent; if (handler != null) { handler(this, e); }

MyEvent.SafeInvoke(this, e);
    

Type Parameters

TEventArgs The type of the class.

Parameters

Name Description
handler The handler.
sender The sender.
fE The event args.

Returns

true if the event handler was notnull; otherwisefalse.

SafeInvoke<TEventArgs>(EventHandler<TEventArgs> handler, object sender, TEventArgs e)

Invokes the specified handler in a thread-safe manner. Where normally one has to write the following code:``` var handler = MyEvent; if (handler != null) { handler(this, e); }

MyEvent.SafeInvoke(this, e);
    

Type Parameters

TEventArgs The type of the class.

Parameters

Name Description
handler The handler.
sender The sender.
e The event args.

Returns

true if the event handler was notnull; otherwisefalse.

UnsubscribeAllHandlers<TEventArgs>(EventHandler<TEventArgs> handler)

Unsubscribes all the handlers from the specified event.

Type Parameters

TEventArgs The type of the event arguments.

Parameters

Name Description
handler The handler.

Have a question about Catel? Use StackOverflow with the Catel tag!


Discussion