Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 957
Swanand Avatar asked Nov 12 '22 23:11

Swanand


1 Answers

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

like image 142
Aleksandar Toplek Avatar answered Nov 15 '22 14:11

Aleksandar Toplek