Stop a thread stuck in a blocking call

I am developing a Windows Forms application to perform several operations on a device connected via USB. For all operations, such as reading, writing and other things, we have a user library.

The recording operation is performed when the user presses the button.

A separate stream is created for reading. The problem with the available library is that the Read call is blocked and has an INFINITE timeout.

In the event of a connection failure, this thread starts when the Read function is called, since this function breaks only if it receives data.

What could be the way to kill this thread in such a scenario? Thread.Abort () does not work.

I am using C # for this programming.

+5
source share
1 answer

This read method probably calls native code, so the stream cannot be interrupted. There is no way (at least I know) to stop a thread that uses COM interop. You might understand why the Read blocking method is primarily used. Try to verify the requirements before calling the read method.

Take a look at this question: Cancel unmanaged DLL call

+1
source

All Articles