07-21-2010 02:59 AM
Hello everybody,
I'm having difficulties aborting async reads so maybe someone here can help me out.
What I'm trying to do: I've setup a PC with a PCI-6518 card (it's old, I admit) which I want to use to receive digital triggers and do some digital I/O with a PLC. Basically the PLC triggers the PC using the 6518-card so I chose the ReadDigChan_ChangeDetection.2008 sample for testing.
Problem: after setting the timeout to -1 since the PC has no idea when the trigger will happen I have obviously troubles to stop the asynchronous read.
I circumvented this by adding
try { myTask.Control(TaskAction.Abort); } catch { } finally { myTask.Stop(); myTask.Dispose(); }
but this leaves me with unpredictable behaviour: mostly it works out fine but after starting and stoping tasks repeatedly I get Windows memory read violation errors or the applications hangs and eats up the CPU.
Any ideas or design patterns on how to use BeginReadSingleSampleMultiLine and aborting these asynchronous reads gracefully?
Help is really appreciated so thanks in advance!
regards,
ahds
07-22-2010 07:45 AM - edited 07-22-2010 07:46 AM
Hi ahds,
what kind of error message do you see? Which DAQmx version are you using?
Aborting a task is not a safe way to stop it. I would suggest you try and stop it right away. Have you seen issues doing that?
Maybe you could help me understand your application a bit better. What determines the end of your read? Could you maybe post some of your code?
Thanks!
Peter
07-23-2010 02:41 AM
Hi PaSB,
I've gone ahead and made a zip (attached) containing my modified example C# project.
What it's basically doing is calling BeginReadSingleSampleMultiLine when the "Start" button is clicked with a timeout of "-1" / infinite.
When "Stop" is clicked the task is aborted, stopped and disposed of. This has to be done to get rid of the "hanging" BeginReadSingleSampleMultiLine call.
Also: After moving this abort code out of the C#-UI-thread (which the code is running in a form control event handler) into a background thread I have not experienced any memory error messages are hanging abort calls on the task anymore.
So is it "safe to assume" that the code in the attached zip is sane in the sense that I can use this pattern elsewhere (in our "real" projects)?
regards and thanks a lot for your time and effort!
ahds
ps: and greetings from Mainz, Germany 🙂
07-26-2010 08:49 AM
"Aborting a task is not a safe way to stop it. I would suggest you try and stop it right away. Have you seen issues doing that?"
The one big issue is that hanging "BeginRead" calls with an infinite timeout hang forever without a call to "Abort".
What would you propose instead?
regards,
ahds
07-30-2010 02:01 AM
Is there anything else I could provide? Was something missing?
Just wondering, regards
ahds
07-30-2010 07:35 AM
Hi ahds,
sorry for replying a bit late. Since you do an infinite wait, you have to abort the task. Maybe you could consider a trigger instead?
Your code should be safe to use. Have you encountered any other issues, yet?
Peter