08-18-2016 06:45 PM
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();
Solved! Go to Solution.
08-19-2016 07:59 AM
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/
08-19-2016 11:41 AM - edited 08-19-2016 11:42 AM
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();
08-19-2016 11:55 AM
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!