|Download Help (Windows Only)|
The NI-DAQmx .NET library supports asynchronous notification of various occurrences using .NET events.
Events in the NI-DAQmx .NET library are located on the Task class. The following events are supported:
Asynchronous I/O vs. Events
The NI-DAQmx .NET library also supports asynchronous I/O, which is similar to events. With asynchronous I/O, you create callbacks to be executed when a read or write operation completes. The NI-DAQmx .NET library also supports the EveryNSamples event. With this event, you create callbacks to be executed after a certain number of samples has been processed. You can also use EveryNSamples to call into certain methods of the task and access properties of the task while the task is still running. For more information, refer to Asynchronous Reads and Writes.
Event Handler Considerations
Some events might occur frequently depending on your task configuration. For example, SampleComplete occurs frequently for input tasks with high sampling rates. Your event handler must execute quickly enough to respond to every NI-DAQmx event, as each one occurs. If your event handler cannot keep up with NI-DAQmx, your NI-DAQmx operation might fail or your program might become unresponsive. If you experience these problems, you should shorten your event handler or reconfigure your task so that events occur less often. For example, if your application cannot keep up with the SampleComplete event, you can use asynchronous I/O to execute callbacks after a larger number of samples have been acquired or generated.
Events are registered at the driver level, and as a result, when working with UI, you have to keep in mind that, if the application closes without the task being stopped, events might still occur while the application attempts to close. In such scenarios, the event will try to be executed on a thread that might have ended already. This will yield an error. To avoid this, remember to stop the task before exiting the application.
Event handlers, in some cases, are executed using the SynchronizationContext of the thread you use to execute the handler.