Sdílet prostřednictvím


AsyncEvent<TEventArgs>.Addition Operator

Definition

Operator += to support standard mechanism of event subscription

public:
 static Microsoft::VisualStudio::Workspace::AsyncEvent<TEventArgs> ^ operator +(Microsoft::VisualStudio::Workspace::AsyncEvent<TEventArgs> ^ e, Func<System::Object ^, TEventArgs, System::Threading::Tasks::Task ^> ^ callback);
public static Microsoft.VisualStudio.Workspace.AsyncEvent<TEventArgs> operator + (Microsoft.VisualStudio.Workspace.AsyncEvent<TEventArgs> e, Func<object,TEventArgs,System.Threading.Tasks.Task> callback);
public static Microsoft.VisualStudio.Workspace.AsyncEvent<TEventArgs> operator + (Microsoft.VisualStudio.Workspace.AsyncEvent<TEventArgs>? e, Func<object?,TEventArgs,System.Threading.Tasks.Task> callback);
static member ( + ) : Microsoft.VisualStudio.Workspace.AsyncEvent<'EventArgs (requires 'EventArgs :> EventArgs)> * Func<obj, 'EventArgs, System.Threading.Tasks.Task (requires 'EventArgs :> EventArgs)> -> Microsoft.VisualStudio.Workspace.AsyncEvent<'EventArgs (requires 'EventArgs :> EventArgs)>
Public Shared Operator + (e As AsyncEvent(Of TEventArgs), callback As Func(Of Object, TEventArgs, Task)) As AsyncEvent(Of TEventArgs)

Parameters

e
AsyncEvent<TEventArgs>

The async event class

callback
Func<Object,TEventArgs,Task>

Async event callback to add

Returns

The existing or created Async event class

Remarks

Using += for initialization of an AsyncEvent object introduces a race condition where, if the AsyncEvent == null and ThreadA and ThreadB both attempt to subscribe simultaneously, then it's possible for one of ThreadA's or ThreadB's subscribe request to be lost. To work around this, one should initialize AsyncEvent objects.

Applies to