Non-Blocking Input Events
Posted: Wed Feb 01, 2023 7:05 pm
I receive events as digital input from an IR device. I want to perform a bunch of things that will run async and take several seconds when the state of the input is true. During this time I will ignore all other state changes on this input.
How can I make this non-blocking on the phidget? I want to immediately return and not "hold" onto the thread that called this event?
Is there any coding pattern or example for this scenario. i.e. running long running tasks from a phidget event?
Code: Select all
private async void DigitalInput_StateChange(object sender, Phidget22.Events.DigitalInputStateChangeEventArgs e)
{
try
{
if (isInitialised)
{
await DigitalInputStatus((DigitalInput)sender, e.State);
}
}
catch (PhidgetException ex)
{
Debug.WriteLine("[ERROR] StateChanged.PhEx " + ex.ErrorCode + " (" + ex.Description + "): " + ex.Detail);
}
}
Is there any coding pattern or example for this scenario. i.e. running long running tasks from a phidget event?