07-20-2017 12:55 AM
Hello, I've written a windows service for change detection using DaqMx 17.0. To avoid throwing timeout exception on BeginReadSingleSampleMultiLine method, I did this at the Task initialization:
myTask.Stream.Timeout = -1; // To avoid unnecessary exception
When I try to stop my service, here comes the problem: the codes were simply blocked on the Dispose method causing the service not able to stop correctly.
public void Dispose()
{
runningTask = null;
myDigitalReader = null;
myTask?.Dispose(); // It blocks here
}
I tried:
public void Dispose()
{
runningTask = null;
myDigitalReader = null;
myTask?.Stream.Timeout=1;
myTask?.Dispose(); //still blocks
}
but no difference. Without the timeout setting, everything works fine. It looks like once the task start, it cannot be stopped or disposed. The program runs under a .NET 4.6 windows service (Windows 10).Can anyone help?
07-21-2017 10:33 AM
Can you try aborting the task before disposing? I don't have a system setup to try it, but it's something like 'myTask.Control(TaskAction.Abort)'.
Hope this helps!
Trent