Click or drag to resize

ScriptingOnEvent Method (ScriptingEventsList, FuncScriptEventArgs, Task, CancellationToken)

Creates an adhoc event binding to act on.

Namespace:  RRAutoLib.Scripting
Assembly:  RRAutoLib (in RRAutoLib.dll) Version: 4.0.8678.28884
Syntax
Public Shared Function OnEvent ( 
	objEvents As ScriptingEventsList,
	delHandler As Func(Of ScriptEventArgs, Task),
	Optional sctCancelToken As CancellationToken = Nothing
) As Task

Parameters

objEvents
Type: RRAutoLib.ScriptingScriptingEventsList
One or more events to be observed.
delHandler
Type: SystemFuncScriptEventArgs, Task
A function to be excuted when any one of the bound events are raised.
sctCancelToken (Optional)
Type: System.ThreadingCancellationToken
Token provided by a controlling source to notify this method that it should cancel its execution.

Return Value

Type: Task
The Task that can be awaited, if execution must halt while the events are bound.
Remarks
This method was designed specifically for use within the scripting context and is only safe to be called on the CTC thread.
Examples
In the following example, execution will halt until either of the two bound sensors report an On state. e2.Sender returns the first object that raised the event (in this example, one of the two bound sensors). Setting e2.Dispose, in the function unbinds the events and completes the task this method returns. The function could optionally be left out in which case the task completes immediately when either event occurs. Optionally the e.CancelToken passed from the hosting script object, can be handed down to this method so it can participate in a cancellation order received from the parent script. Note that although both e. and e2. are ScriptEventArgs, they are given different names to disambiguate the upstream event argument from the downstream one.
VB
Await OnEvent(New EventsList() From {
    {CtcSensor("Sensor1"), "StateReported"}, 
    {CtcSensor("Sensor2"), "StateReported"}},
    Function(e2 as ScriptEventArgs)
        If e2.Sender.State = 1 Then e2.Dispose()
    End Function,
    e.CancelToken)
See Also