Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Task cannot be disposed after setting timeout=-1

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?

 

0 Kudos
Message 1 of 2
(2,652 Views)

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

https://www.linkedin.com/in/trentweaver
Message 2 of 2
(2,619 Views)