03-24-2008 03:37 PM
03-24-2008 05:50 PM
Hi karenho,
Its not clear from your post exactly what the problem you are having is so
allow me to suggest and ask a few things.
1) Have you taken a look at our synchronization examples in the following directories:
Windows Vista - C:\Users\Public\Documents\National
Instruments\NI-DAQ\Examples\DotNET2.0\Synchronization
Windows XP - C:\Documents and Settings\All
Users\Documents\National Instruments\NI-DAQ\Examples\DotNET2.0\Synchronization
These example should give you a good starting point
2) When you click the stop button, what code does the stop button actually
perform?
Are you calling Task.Stop or Task.Dispose?
What task does it stop? The AO task or AI task?
3) When you click the stop button, you say that the UI is non-responsive but
you are still reading data?
4) Does this issue occur both in release or debug mode?
I don't want to start guessing to much as your problem is still unclear to me.
A small example would always help.
Best Regards,
03-25-2008 02:42 PM
Here is an example of what I'm trying to do. When you activate the stop button, it should set bStopTest to true. Then, when function() gets to the point where it checks on bStopTest, function() should abort the tasks and exit. Instead, it keeps going and ignores that bStopTest is set -- meaning bStopTest is never set to true. The UI also freezes at this point until function() is done. The program doesn't freeze just the UI.
Even if you were to activate the stop button before the program goes into function(), bStopTest is false. But if I put this "bStopTest = true" right before "if(bStopTest == true)" in function(), it'll abort the tasks.
I don't think this is a synchronization problem. This is in debug mode, did not try release mode.
==============================
private void stopTest_Click(object sender, System.EventArgs e) // stop button
{
bStopTest = true;
}
public void function()
{
Task2.Start(); // analog inputs
Task2Writer.WriteSingleSample(true, Data[0]);
for(...)
{
Task2.WriteSingleSample(true, Data[j]);
Thread.Sleep(100);
Reader.ReadSingleSample();
if(bStopTest == true) // it never gets to this point
{
Task1.Control(TaskAction.Abort);
Task2.Control(TaskAction.Abort);
return;
}
// do something....
}
}
03-25-2008 04:31 PM
03-26-2008 10:03 AM
so does something like this work because it doesn't work for me. i got the same result. thanks.
====================
double[] data = new double[4];
double[] readData = new double[4];
private void stopTest_Click(object sender, System.EventArgs e) // stop button
{
bStopTest = true;
}
public void function()
{
Task2.Start(); // analog inputs
Task2Writer.WriteSingleSample(true, Data[0]);
Task1Reader.BeginReadSingleSample(new AsyncCallback (callBackFunc), null);
for(...)
{
Task2.WriteSingleSample(true, Data[j]);
Thread.Sleep(100);
data = readData;
if(bStopTest == true) // it never gets to this point
{
Task1.Control(TaskAction.Abort);
Task2.Control(TaskAction.Abort);
return;
}
// if not bStopTest do something....
}
}
public void callBackFunc(IAsyncResult i)
{
readData = Task1Reader.EndReadSingleSample(i);
Task1Reader.BeginReadSingleSample(new AsyncCallback (callBackFunc), null);
}
03-27-2008 12:49 PM