Task Class
- Updated2026-02-05
- 4 minute(s) read
Represents a collection of virtual channels and their per-channel properties and timing, triggering, and other properties that apply to the DAQmx Task.
Derives from
- MarshalByRefObject
- IDisposable
- ISynchronizeCallbacks
- ISupportSynchronizationContext
Syntax
Namespace: NationalInstruments.DAQmx
public class Task : MarshalByRefObject, IDisposable, ISynchronizeCallbacks, ISupportSynchronizationContext
Remarks
Some DAQ devices are not currently supported by the NI-DAQmx driver. Refer to NI-DAQ Readme for a complete listing of supported hardware.
Example applications are located in the <Public Documents>\National Instruments\NI-DAQ\Examples\DotNET4.x directory or in the Start menu at National Instruments»NI-DAQmx»NI-DAQmx Examples.
Tasks
Thread Safety
All members of this type are safe for multithreaded operations.
Constructors
| Name | Description |
|---|---|
| Task() | Initializes a new instance of the Task class with a unique name. |
| Task(string) | Initializes a new instance of the Task class with the specified name. |
Properties
| Name | Description |
|---|---|
| AccessoryInsertionOrRemovalDetected | Indicates if any devices in the task detected the insertion or removal of an accessory since the task started. Reading this property clears the accessory change status for all channels in the task. You must read this property before you read DevicesWithInsertedOrRemovedAccessories. Otherwise, you will receive an error. |
| AIChannels | Gets the collection of analog input channels in the task. |
| AOChannels | Gets the collection of analog output channels in the task. |
| CIChannels | Gets the collection of counter input channels in the task. |
| COChannels | Gets the collection of counter output channels in the task. |
| Devices | Indicates an array containing the names of all devices in the task. |
| DevicesWithInsertedOrRemovedAccessories | Indicates the names of any devices that detected the insertion or removal of an accessory since the task started. You must read AccessoryInsertionOrRemovalDetected before you read this property. Otherwise, you will receive an error. |
| DIChannels | Gets the collection of digital input channels in the task. |
| DOChannels | Gets the collection of digital output channels in the task. |
| EveryNSamplesReadEventInterval | Gets or sets the interval, in number of samples per channel, at which EveryNSamplesRead is called. |
| EveryNSamplesWrittenEventInterval | Gets or sets the interval, in number of samples per channel, at which EveryNSamplesWritten is called. |
| ExportSignals | Gets the exported signal configuration for the task. |
| IsDone | Indicates whether the task completed execution. |
| Name | Indicates the name of the task. |
| Stream | Gets the stream for the task. |
| SwitchScan | Gets the switch scan configuration for the task. |
| SynchronizeCallbacks | Specifies how events and callback delegates are invoked. |
| SynchronizingObject | Obsolete: Use SynchronizeCallbacks to specify that the object marshals callbacks across threads appropriately. Will warn if used |
| Timing | Gets the timing configurations for the task. |
| Triggers | Gets the triggers for the task. |
| Watchdog | Gets the watchdog configuration and control object for the task. |
Methods
| Name | Description |
|---|---|
| AddGlobalChannel(string) | Adds a preconfigured, global channel to the task. |
| ConfigureLogging(string, TdmsLoggingOperation, LoggingMode) | Configures logging to a .tdms file when the acquisition starts. |
| ConfigureLogging(string, TdmsLoggingOperation, LoggingMode, string) | Configures logging to a .tdms file when the acquisition starts with the specified TDMS channel group name. |
| Control(TaskAction) | Alters the state of the task according to the mode you specify. |
| Dispose() | Releases all resources used by Task. |
| Start() | Transitions the task to the running state, which begins the measurement or generation. |
| StartNewFile(string) | Starts a new TDMS file the next time data is written to disk. |
| Stop() | Transitions the task from the running to the committed state, which ends the measurement or generation. |
| ToString() | Returns a string representation of the object. |
| WaitForValidTimestamp(TimestampEvent) | Waits indefinitely until the specified timestampEvent has a value. |
| WaitForValidTimestamp(TimestampEvent, TimeSpan) | Waits until the specified timestampEvent has a value. |
| WaitUntilDone(TimeSpan) | Waits for the measurement or generation to complete and returns if it has completed execution before the specified TimeSpan elapses. |
| WaitUntilDone() | Waits for the measurement or generation to complete, regardless of the amount of time needed, and returns if it has completed execution. |
| WaitUntilDone(int) | Waits for the measurement or generation to complete and returns if it has completed execution before the specified time elapses. |
| Dispose(bool) | Releases the managed and unmanaged resources used by Task or optionally releases only the unmanaged resources. |
Events
| Name | Description |
|---|---|
| CounterOutput | Occurs when any of the counters used in the task reaches its terminal count. |
| DigitalChangeDetection | Occurs when a digital change is detected on any of the digital lines used in the task. |
| Done | Occurs when the task completes. |
| EveryNSamplesRead | Occurs when N number of samples per channel, as defined by EveryNSamplesReadEventInterval, is written from the device to the PC buffer. |
| EveryNSamplesWritten | Occurs when N number of samples per channel, as defined by EveryNSamplesWrittenEventInterval, have been written from the PC buffer to the device. |
| SampleClock | Occurs on each pulse of the task's sample clock. |
| SampleComplete | Occurs when each sample is acquired into the NI-DAQmx driver buffer and is ready for reading. |
See Also
- LoadTask(string)
- AnalogSingleChannelReader
- AnalogMultiChannelReader
- AnalogUnscaledReader
- CounterSingleChannelReader
- CounterMultiChannelReader
- DigitalSingleChannelReader
- DigitalMultiChannelReader
- AnalogSingleChannelWriter
- AnalogMultiChannelWriter
- AnalogUnscaledWriter
- DigitalSingleChannelWriter
- DigitalMultiChannelWriter