ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

AccessViolationException when async callback has timeout

Hi

I have a 6602 card where each of 5 counters are hooked up to measure pulsewidts on their inputs.

Each task has the same timeout.

 

After createing the task and corresponding counter readers and AsyncCallbacks I start an async read of 10 samples on each task.

 

Now to may problem. If I start these async reads right after eachother like

 

reader1.BeginReadMultiSampleDouble(10, ACallback, null);

reader2.BeginReadMultiSampleDouble(10, ACallback2, null);

 

When there is no pulsewidths to measure the async read has a timeout. At that point I receive the following Exception in the callback

 

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

 

  at NationalInstruments.DAQmx.Internal.DaqAsyncResult.ThrowAsyncException()
   at NationalInstruments.DAQmx.Internal.CounterMultiSampleDoubleReadAsyncResult.End()
   at NationalInstruments.DAQmx.Internal.CounterReaderImpl.EndReadMultiSampleDouble(IAsyncResult asyncResult)
   at NationalInstruments.DAQmx.CounterReader.EndReadMultiSampleDouble(IAsyncResult asyncResult)
   at AR4000_Test.IO.DataAcquisitionBase.ReadPulseWidthCallback(IAsyncResult ar) in C:\Users\joj\Documents\Visual Studio 2008\TestProjects\AR4000 Test\AR4000 Test\IO\DataAcquisitionBase.cs:line 78

If I insert a delay of 20ms, so timeouts will occurr 20ms apart I do not receive the exception.

 

reader1.BeginReadMultiSampleDouble(10, ACallback, null);

Thread.Sleep(20);

reader2.BeginReadMultiSampleDouble(10, ACallback2, null);

 

This is clearly not a solution since I cannot be sure that timeouts later will drift towards eachother causing the same exception.

I can also catch the exception and continue, but since I do not know what causes the Exception I rather not just eat it and continue.

 

Why is this happening and what can I do to prevent it.

 

BR

Jonas

 

 

0 Kudos
Message 1 of 2
(4,044 Views)

Hi Jonas

 

I would start by having a look at this thread and try some of the things they recommend in there. What version of MStudio, VS and DAQmx are you using?

 

Best Regards

 

David

NISW

0 Kudos
Message 2 of 2
(4,027 Views)