Swanand
Swanand

Reputation: 4115

Stop a thread stuck at a blocking call

I am developing a Windows Forms Application to perform few operations on a device connected via USB. For All operations like Read, Write and other things, we have a custom library.

Write operation is done when User hits a button.

To read, a Separate thread is created. Problem with available library is that the Read call is blocking and has INFINITE Timeout.

In case of connection failure, this thread stucks at Read function call as this function breaks only if it recieves data.

What could be the way to Kill this thread in such scenario? Thread.Abort() is not working.

I am using C# for this programming.

Upvotes: 5

Views: 1494

Answers (1)

Aleksandar Toplek
Aleksandar Toplek

Reputation: 2831

That Read method of yours probably calls native code so thread can't abort. There is no way (at least that I am familiar with) to abort thread that uses COM interop. You could look why is Read method blocking thread in the first place. Try to check for requirements before calling Read method.

Take a look at this question: Abort call to unmanaged DLL

Upvotes: 1

Related Questions