Class AsyncEvent<TSender, TArgs>
Implementation of asynchronous event. The handlers of such events are executed asynchronously, but sequentially.
Inherited Members
Namespace: DisCatSharp.Common.Utilities
Assembly: DisCatSharp.Common.dll
Syntax
public sealed class AsyncEvent<TSender, TArgs> : AsyncEvent where TArgs : AsyncEventArgs
Type Parameters
Name | Description |
---|---|
TSender | Type of the object that dispatches this event. |
TArgs | Type of event argument object passed to this event's handlers. |
Constructors
| Improve this Doc View SourceAsyncEvent(String, TimeSpan, AsyncEventExceptionHandler<TSender, TArgs>)
Creates a new asynchronous event with specified name and exception handler.
Declaration
public AsyncEvent(string name, TimeSpan maxExecutionTime, AsyncEventExceptionHandler<TSender, TArgs> exceptionHandler)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of this event. |
System.TimeSpan | maxExecutionTime | Maximum handler execution time. A value of System.TimeSpan.Zero means infinite. |
AsyncEventExceptionHandler<TSender, TArgs> | exceptionHandler | Delegate which handles exceptions caused by this event. |
Properties
| Improve this Doc View SourceMaximumExecutionTime
Gets the maximum allotted execution time for all handlers. Any event which causes the handler to time out will raise a non-fatal AsyncEventTimeoutException<TSender, TArgs>.
Declaration
public TimeSpan MaximumExecutionTime { get; }
Property Value
Type | Description |
---|---|
System.TimeSpan |
Methods
| Improve this Doc View SourceInvokeAsync(TSender, TArgs, AsyncEventExceptionMode)
Raises this event by invoking all of its registered handlers, in order of registration.
All exceptions throw during invocation will be handled by the event's registered exception handler.
Declaration
public async Task InvokeAsync(TSender sender, TArgs e, AsyncEventExceptionMode exceptionMode = AsyncEventExceptionMode.HandleAll)
Parameters
Type | Name | Description |
---|---|---|
TSender | sender | Object which raised this event. |
TArgs | e | Arguments for this event. |
AsyncEventExceptionMode | exceptionMode | Defines what to do with exceptions caught from handlers. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Register(AsyncEventHandler<TSender, TArgs>)
Registers a new handler for this event.
Declaration
public void Register(AsyncEventHandler<TSender, TArgs> handler)
Parameters
Type | Name | Description |
---|---|---|
AsyncEventHandler<TSender, TArgs> | handler | Handler to register for this event. |
Unregister(AsyncEventHandler<TSender, TArgs>)
Unregisters an existing handler from this event.
Declaration
public void Unregister(AsyncEventHandler<TSender, TArgs> handler)
Parameters
Type | Name | Description |
---|---|---|
AsyncEventHandler<TSender, TArgs> | handler | Handler to unregister from the event. |
UnregisterAll()
Unregisters all existing handlers from this event.
Declaration
public void UnregisterAll()