-
Notifications
You must be signed in to change notification settings - Fork 5
Description
When a workflow is stopped, the readFrames Task withing ContextTask is cancelled. This in turn ends the acquisition Task, which is linked to the lifetime of readFrames via a WhenAll. The end of the acquisition task indicates the end of acqusition and thus that the underlying oni context can be destroyed. This is performed with an asynchronous continuation:
bonsai-onix1/OpenEphys.Onix1/ContextTask.cs
Line 580 in 1b0d4b7
| acquisition.ContinueWith(_ => DisposeContext()); |
If another ContextTask is created, and its constructor called, when this continuation is executing, then ctx = new oni.Context(contextDriver, contextIndex); can be called against hardware that is not completely freed by the original ContextTask. This can result in an "Attempt to trigger and already triggered operation" exception.
To prevent this, DisposeContext() must complete execution before the ContextTask.Dispose() returns. This can done using Wait() or GetAwaiter().GetResult() on the continuation task. The later will not mangle an exception that is thrown from DisposeContext().