Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Running two tasks that share the same resource in sequence

Solved!
Go to solution

I am getting the common "The specified resource is reserved." exception. I understand that you cannot run two tasks that share the same resource concurrently. However, is it true that you cannot run two tasks that share the same resource, one right after the other, without completely disposing of the first task?

 

e.g.

// task1 and task2 share the same resource
task1.Start();
task1.Stop();
task2.Start(); // This will always throw an exception until you dispose of task1 (i.e. task1.Dispose())??
task2.Stop();

 

0 Kudos
Message 1 of 4
(3,226 Views)
Solution
Accepted by cafarm

Hi cafarm,

You are correct that simply stopping one task will not allow you run another task with the same resources immediately after. That being said, you can start the next task without having to clear or dispose of the first one by making use of the DAQmx Task State Model. As you can see on the following page, stopping a task simply transitions to the "Committed" state, which means the hardware is still in use by the task even though it is not actively running. 

http://zone.ni.com/reference/en-XX/help/370466AC-01/mxcncpts/taskstatemodel/

Instead, you can use the Task Control functionality to transition the first Task back into the "verified" state after stopping it, then start the second task. This keeps the task settings without having to dispose of the task, but should free up your resources to be used by other tasks.
http://zone.ni.com/reference/en-XX/help/370473H-01/mstudiowebhelp/html/verifycommitstartstopdaqtask/

Charlie J.
National Instruments
Message 2 of 4
(3,198 Views)

Thank you Charlie, that's what I needed.

 

Just a note: I had to put the first task into the "unreserved" state before it would allow me to use the second task. Placing the task into "verified" state did not appear to be sufficient.

 

// task1 and task2 share the same resource
task1.Start();
task1.Stop();
task1.Control(TaskAction.Unreserve); // This allows you to use the second task without disposing of the first task
task2.Start();
task2.Stop();

 

0 Kudos
Message 3 of 4
(3,189 Views)

Hi cafarm,

Glad that worked! I believe based on the state model that "unreserve" transitions to the verified state. I gave you the wrong suggestion, as verified is for transitioning from unverified to verified, and we needed to get there from the opposite direction. Sorry for the confusion! 

Charlie J.
National Instruments
0 Kudos
Message 4 of 4
(3,184 Views)