,--0},System.Action{--0},System.Action{--0})} ,--0},System.Action{--0},System.Action{--0},System.Reactive.Concurrency.IScheduler)} ,System.Action{--0})} ,System.Action{--0},System.Reactive.Concurrency.IScheduler)} },System.Action{System.Action{--0}})} },System.Action{System.Action{--0}},System.Reactive.Concurrency.IScheduler)} ,System.Action{System.Action})} ,System.Action{System.Action},System.Reactive.Concurrency.IScheduler)}
Observable.FromEvent(Func, TDelegate>, Action, Action) method¶
Defined in
Type: Observable
Namespace: System.Reactive.Linq
Assembly: System.Reactive.dll
Applies to
netstandard2.0
Overloads¶
- 1.
public static IObservable<TEventArgs> FromEvent<TDelegate, TEventArgs>(Func<Action<TEventArgs>, TDelegate> conversion, Action<TDelegate> addHandler, Action<TDelegate> removeHandler) - 2.
public static IObservable<TEventArgs> FromEvent<TDelegate, TEventArgs>(Func<Action<TEventArgs>, TDelegate> conversion, Action<TDelegate> addHandler, Action<TDelegate> removeHandler, IScheduler scheduler) - 3.
public static IObservable<TEventArgs> FromEvent<TDelegate, TEventArgs>(Action<TDelegate> addHandler, Action<TDelegate> removeHandler) - 4.
public static IObservable<TEventArgs> FromEvent<TDelegate, TEventArgs>(Action<TDelegate> addHandler, Action<TDelegate> removeHandler, IScheduler scheduler) - 5.
public static IObservable<TEventArgs> FromEvent<TEventArgs>(Action<Action<TEventArgs>> addHandler, Action<Action<TEventArgs>> removeHandler) - 6.
public static IObservable<TEventArgs> FromEvent<TEventArgs>(Action<Action<TEventArgs>> addHandler, Action<Action<TEventArgs>> removeHandler, IScheduler scheduler) - 7.
public static IObservable<Unit> FromEvent(Action<Action> addHandler, Action<Action> removeHandler) - 8.
public static IObservable<Unit> FromEvent(Action<Action> addHandler, Action<Action> removeHandler, IScheduler scheduler)
1. Overload¶
public static IObservable<TEventArgs> FromEvent<TDelegate, TEventArgs>(Func<Action<TEventArgs>, TDelegate> conversion, Action<TDelegate> addHandler, Action<TDelegate> removeHandler)
Summary: Converts a .NET event to an observable sequence, using a conversion function to obtain the event delegate. Each event invocation is surfaced through an OnNext message in the resulting sequence. For conversion of events conforming to the standard .NET event pattern, use any of the FromEventPattern overloads instead.
Type parameters
| Name | Description |
|---|---|
TDelegate | The delegate type of the event to be converted. |
TEventArgs | The type of the event data generated by the event. |
Parameters
| Name | Type | Description |
|---|---|---|
conversion | Func | A function used to convert the given event handler to a delegate compatible with the underlying .NET event. The resulting delegate is used in calls to the addHandler and removeHandler action parameters. |
addHandler | Action | Action that attaches the given event handler to the underlying .NET event. |
removeHandler | Action | Action that detaches the given event handler from the underlying .NET event. |
Returns: IObservable
Remarks
Add and remove handler invocations are made whenever the number of observers grows beyond zero. As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
The current SynchronizationContext is captured during the call to FromEvent, and is used to post add and remove handler invocations. This behavior ensures add and remove handler operations for thread-affine events are accessed from the same context, as required by some UI frameworks.
If no SynchronizationContext is present at the point of calling FromEvent, add and remove handler invocations are made synchronously on the thread making the Subscribe or Dispose call, respectively.
It's recommended to lift FromEvent calls outside event stream query expressions due to the free-threaded nature of Reactive Extensions. Doing so makes the captured SynchronizationContext predictable. This best practice also reduces clutter of bridging code inside queries, making the query expressions more concise and easier to understand.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | conversion or addHandler or removeHandler is null. |
See also
2. Overload¶
public static IObservable<TEventArgs> FromEvent<TDelegate, TEventArgs>(Func<Action<TEventArgs>, TDelegate> conversion, Action<TDelegate> addHandler, Action<TDelegate> removeHandler, IScheduler scheduler)
Summary: Converts a .NET event to an observable sequence, using a conversion function to obtain the event delegate. Each event invocation is surfaced through an OnNext message in the resulting sequence. For conversion of events conforming to the standard .NET event pattern, use any of the FromEventPattern overloads instead.
Type parameters
| Name | Description |
|---|---|
TDelegate | The delegate type of the event to be converted. |
TEventArgs | The type of the event data generated by the event. |
Parameters
| Name | Type | Description |
|---|---|---|
conversion | Func | A function used to convert the given event handler to a delegate compatible with the underlying .NET event. The resulting delegate is used in calls to the addHandler and removeHandler action parameters. |
addHandler | Action | Action that attaches the given event handler to the underlying .NET event. |
removeHandler | Action | Action that detaches the given event handler from the underlying .NET event. |
scheduler | [IScheduler](# | The scheduler to run the add and remove event handler logic on. |
Returns: IObservable
Remarks
Add and remove handler invocations are made whenever the number of observers grows beyond zero. As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
Add and remove handler invocations are run on the specified scheduler. This behavior allows add and remove handler operations for thread-affine events to be accessed from the same context, as required by some UI frameworks.
It's recommended to lift FromEvent calls outside event stream query expressions. This best practice reduces clutter of bridging code inside queries, making the query expressions more concise and easier to understand. This has additional benefits for overloads of FromEvent that omit the IScheduler parameter. For more information, see the remarks section on those overloads.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | conversion or addHandler or removeHandler or scheduler is null. |
See also
3. Overload¶
public static IObservable<TEventArgs> FromEvent<TDelegate, TEventArgs>(Action<TDelegate> addHandler, Action<TDelegate> removeHandler)
Summary: Converts a .NET event to an observable sequence, using a supplied event delegate type. Each event invocation is surfaced through an OnNext message in the resulting sequence. For conversion of events conforming to the standard .NET event pattern, use any of the FromEventPattern overloads instead.
Type parameters
| Name | Description |
|---|---|
TDelegate | The delegate type of the event to be converted. |
TEventArgs | The type of the event data generated by the event. |
Parameters
| Name | Type | Description |
|---|---|---|
addHandler | Action | Action that attaches the given event handler to the underlying .NET event. |
removeHandler | Action | Action that detaches the given event handler from the underlying .NET event. |
Returns: IObservable
Remarks
Add and remove handler invocations are made whenever the number of observers grows beyond zero. As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
The current SynchronizationContext is captured during the call to FromEvent, and is used to post add and remove handler invocations. This behavior ensures add and remove handler operations for thread-affine events are accessed from the same context, as required by some UI frameworks.
If no SynchronizationContext is present at the point of calling FromEvent, add and remove handler invocations are made synchronously on the thread making the Subscribe or Dispose call, respectively.
It's recommended to lift FromEvent calls outside event stream query expressions due to the free-threaded nature of Reactive Extensions. Doing so makes the captured SynchronizationContext predictable. This best practice also reduces clutter of bridging code inside queries, making the query expressions more concise and easier to understand.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | addHandler or removeHandler is null. |
See also
4. Overload¶
public static IObservable<TEventArgs> FromEvent<TDelegate, TEventArgs>(Action<TDelegate> addHandler, Action<TDelegate> removeHandler, IScheduler scheduler)
Summary: Converts a .NET event to an observable sequence, using a supplied event delegate type. Each event invocation is surfaced through an OnNext message in the resulting sequence. For conversion of events conforming to the standard .NET event pattern, use any of the FromEventPattern overloads instead.
Type parameters
| Name | Description |
|---|---|
TDelegate | The delegate type of the event to be converted. |
TEventArgs | The type of the event data generated by the event. |
Parameters
| Name | Type | Description |
|---|---|---|
addHandler | Action | Action that attaches the given event handler to the underlying .NET event. |
removeHandler | Action | Action that detaches the given event handler from the underlying .NET event. |
scheduler | [IScheduler](# | The scheduler to run the add and remove event handler logic on. |
Returns: IObservable
Remarks
Add and remove handler invocations are made whenever the number of observers grows beyond zero. As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
Add and remove handler invocations are run on the specified scheduler. This behavior allows add and remove handler operations for thread-affine events to be accessed from the same context, as required by some UI frameworks.
It's recommended to lift FromEvent calls outside event stream query expressions. This best practice reduces clutter of bridging code inside queries, making the query expressions more concise and easier to understand. This has additional benefits for overloads of FromEvent that omit the IScheduler parameter. For more information, see the remarks section on those overloads.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | addHandler or removeHandler or scheduler is null. |
See also
5. Overload¶
public static IObservable<TEventArgs> FromEvent<TEventArgs>(Action<Action<TEventArgs>> addHandler, Action<Action<TEventArgs>> removeHandler)
Summary: Converts a generic Action-based .NET event to an observable sequence. Each event invocation is surfaced through an OnNext message in the resulting sequence. For conversion of events conforming to the standard .NET event pattern, use any of the FromEventPattern overloads instead.
Type parameters
| Name | Description |
|---|---|
TEventArgs | The type of the event data generated by the event. |
Parameters
| Name | Type | Description |
|---|---|---|
addHandler | Action | Action that attaches the given event handler to the underlying .NET event. |
removeHandler | Action | Action that detaches the given event handler from the underlying .NET event. |
Returns: IObservable
Remarks
Add and remove handler invocations are made whenever the number of observers grows beyond zero. As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
The current SynchronizationContext is captured during the call to FromEvent, and is used to post add and remove handler invocations. This behavior ensures add and remove handler operations for thread-affine events are accessed from the same context, as required by some UI frameworks.
If no SynchronizationContext is present at the point of calling FromEvent, add and remove handler invocations are made synchronously on the thread making the Subscribe or Dispose call, respectively.
It's recommended to lift FromEvent calls outside event stream query expressions due to the free-threaded nature of Reactive Extensions. Doing so makes the captured SynchronizationContext predictable. This best practice also reduces clutter of bridging code inside queries, making the query expressions more concise and easier to understand.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | addHandler or removeHandler is null. |
See also
6. Overload¶
public static IObservable<TEventArgs> FromEvent<TEventArgs>(Action<Action<TEventArgs>> addHandler, Action<Action<TEventArgs>> removeHandler, IScheduler scheduler)
Summary: Converts a generic Action-based .NET event to an observable sequence. Each event invocation is surfaced through an OnNext message in the resulting sequence. For conversion of events conforming to the standard .NET event pattern, use any of the FromEventPattern overloads instead.
Type parameters
| Name | Description |
|---|---|
TEventArgs | The type of the event data generated by the event. |
Parameters
| Name | Type | Description |
|---|---|---|
addHandler | Action | Action that attaches the given event handler to the underlying .NET event. |
removeHandler | Action | Action that detaches the given event handler from the underlying .NET event. |
scheduler | [IScheduler](# | The scheduler to run the add and remove event handler logic on. |
Returns: IObservable
Remarks
Add and remove handler invocations are made whenever the number of observers grows beyond zero. As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
Add and remove handler invocations are run on the specified scheduler. This behavior allows add and remove handler operations for thread-affine events to be accessed from the same context, as required by some UI frameworks.
It's recommended to lift FromEvent calls outside event stream query expressions. This best practice reduces clutter of bridging code inside queries, making the query expressions more concise and easier to understand. This has additional benefits for overloads of FromEvent that omit the IScheduler parameter. For more information, see the remarks section on those overloads.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | addHandler or removeHandler or scheduler is null. |
See also
7. Overload¶
public static IObservable<Unit> FromEvent(Action<Action> addHandler, Action<Action> removeHandler)
Summary: Converts an Action-based .NET event to an observable sequence. Each event invocation is surfaced through an OnNext message in the resulting sequence. For conversion of events conforming to the standard .NET event pattern, use any of the FromEventPattern overloads instead.
Parameters
| Name | Type | Description |
|---|---|---|
addHandler | Action | Action that attaches the given event handler to the underlying .NET event. |
removeHandler | Action | Action that detaches the given event handler from the underlying .NET event. |
Returns: IObservable
Remarks
Add and remove handler invocations are made whenever the number of observers grows beyond zero. As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
The current SynchronizationContext is captured during the call to FromEvent, and is used to post add and remove handler invocations. This behavior ensures add and remove handler operations for thread-affine events are accessed from the same context, as required by some UI frameworks.
If no SynchronizationContext is present at the point of calling FromEvent, add and remove handler invocations are made synchronously on the thread making the Subscribe or Dispose call, respectively.
It's recommended to lift FromEvent calls outside event stream query expressions due to the free-threaded nature of Reactive Extensions. Doing so makes the captured SynchronizationContext predictable. This best practice also reduces clutter of bridging code inside queries, making the query expressions more concise and easier to understand.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | addHandler or removeHandler is null. |
See also
8. Overload¶
public static IObservable<Unit> FromEvent(Action<Action> addHandler, Action<Action> removeHandler, IScheduler scheduler)
Summary: Converts an Action-based .NET event to an observable sequence. Each event invocation is surfaced through an OnNext message in the resulting sequence. For conversion of events conforming to the standard .NET event pattern, use any of the FromEventPattern overloads instead.
Parameters
| Name | Type | Description |
|---|---|---|
addHandler | Action | Action that attaches the given event handler to the underlying .NET event. |
removeHandler | Action | Action that detaches the given event handler from the underlying .NET event. |
scheduler | [IScheduler](# | The scheduler to run the add and remove event handler logic on. |
Returns: IObservable
Remarks
Add and remove handler invocations are made whenever the number of observers grows beyond zero. As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
Add and remove handler invocations are run on the specified scheduler. This behavior allows add and remove handler operations for thread-affine events to be accessed from the same context, as required by some UI frameworks.
It's recommended to lift FromEvent calls outside event stream query expressions. This best practice reduces clutter of bridging code inside queries, making the query expressions more concise and easier to understand. This has additional benefits for overloads of FromEvent that omit the IScheduler parameter. For more information, see the remarks section on those overloads.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | addHandler or removeHandler or scheduler is null. |
See also