01-13-2011 04:21 AM
I have a digital out line that needs to be reset with different triggering settings depending on some user options (either triggering off a digital edge or no triggering). First time around I can create the task no problem. But when I then dispose of the task and recreate it, I cannot Start it. I get the error -200587. My .net code is below
//THIS CODE RUNS ONCE
t = new Task();
t.DOChannels.CreateChannel(line, name, ChannelLineGrouping.OneChannelForEachLine);
Writer = new DigitalSingleChannelWriter(t.Stream);
t.Control(TaskAction.Verify);
t.Start();
Writer.WriteSingleSampleSingleLine(true, On);
//THIS CODE IS REPEATED
if (t != null)
{
t.Dispose();
}
if (t != null)
{
t.Control(TaskAction.Abort);
t.Dispose();
}
else
{
t = new Task();
}
t.DOChannels.CreateChannel(line, name, ChannelLineGrouping.OneChannelForEachLine);
Writer = new DigitalSingleChannelWriter(t.Stream);
t.Control(TaskAction.Verify);
t.Control(TaskAction.Commit); *****Error occurs here on second time around*****
t.Stream.WriteRegenerationMode = WriteRegenerationMode.DoNotAllowRegeneration;
t.Start();
Writer.BeginWriteWaveform(true, waveform, null, t);
One odd thing I've noticed is that the error occurs exactly 2 out of 3 times, ie: + - - + - - + - - ...
Any ideas? Or maybe I can get what I need here another way?
Solved! Go to Solution.
01-13-2011 06:46 AM
I've been doing some debugging of this. In the OP I posted just the basic code, removing all the methods and referenced objects so that it would be easier to understand. When I wrote a program in this manner (everything in a single class, no referenced objects), the problem seems to go away.
It seems like there is something that is delaying the proper disposal of the tasks.
In my original code I have a "DigitalOutputChannel" class which encompasses the task and all its companions. I realized that I was actually making a copy of this every time I cycled through the code, instead of simply reusing it and remaking the task. It's possible the .net garbage disposal was not working until every third run through, allowing it to function again properly.
The code now works!