One thing to look out for would be how you manipulate the UI controls in the BeginVIDataRead method. You will run into problems if you try and access UI controls in a thread other than the one it was created in. BeginInvoke, EndInvoke, Invoke, InvokeRequired, and CreateGraphics are the only members of the UI controls that are thread safe.
The reason why the example does not do this for the graph control in the AnalogInCallback method is because we specify the synchronizing object of the analogInReader to be the form itself.
analogInReader.SynchronizingObject = this;
This ensures that the callback will occur in the same thread as the form itself. Check out the Help topic "Asynchronously Reading and Writing with the NI-DAQmx .NET Class Library" for more information. The DAQmx .NET API help is integrated into the Visual Studio 2003 Help.
What might be happening is that the async callback in the user control might not have completed by the time you call start again. The documentation for Task.Stop states
If an asynchronous read or write on the task is in progress, Stop does not return until the data from the pending read or write has been transferred to or from the task buffer. Stop does not wait for read or write asynchronous callback methods to finish, however.The usercontrol sets up the task and async callbacks for you. You don't have to configure the timing and callbacks for a task that is returned to you by the user control. If you look at the code for the user control, its already doing that for you. This code is in the DAQmxTask1.cs. This code is autogenerated for you when you use the DAQ Assistant to generate the configuration code for you.
The DAQmx shipping example sets up the async callsbacks explicitly because its not done anywhere else. If you want to follow the pattern that the examples are using, I would recommend just using the configured tasks returned to you by the DAQmxTask1 class and then setting up the asyc callbacks yourself. Because it looks like you basically recreate the same code that is already present in the usercontrol inside your BeginVIDataRead method. When you call this.daQmxUserControl11.Start(), you start up the async callbacks in the user control.
So you can try using either the usercontrol to return the data to you, or use the configured task and then follow the pattern that the examples use.But I think the problem might be happening because of the multiple BeginReads that are being called on the same task. The daqmxUsercontrol stop might only be stopping one of the reads but not the ones that you started up.
I hope this helps. Let me know if missed anything or if something was not clear.
Bilal Durrani
NI