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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With