I am writing a program in C# which is interfacing with a small display unit that does a whole bunch of stuff that's not relevant to this problem.
The problem I have is detailed as follows: When the user selects a button which will attempt to SAVE some settings to the device, it uses an acknowledgement protocol to be sure that the settings went through (Meaning -- It sends settings then waits for acknowledgement packet from the device.)
What I do is I generate a thread in my main application which is going to be the "parent" thread of the threads I am about to generate which will attempt to save to the device. Currently, it works in the following manner:
Generate Thread 1 -> Try to save.
If timed out, Interrupt Thread 1 (to release the data lock of the device) via Thread.Interrupt() <----- this is the problem. This doesn't work. It bolds the lock until the device is shut off or unplugged then it errors out. (Then it would gen a new thread, which happens now but it never works because the first thread still locking out the data).
If it didn't time out, the callback for thread 1 lets the parent thread know not to generate any more threads.
Finally, if none of the threads succeeded then the overall attempt failed.
I have also tried doing this with just a single thread being generated and shut down, which also exhibits the same behavior where when waiting for an acknowledgement from the device it hangs permanently until the device is powered off or unplugged.
There is no way to encapsulate that waiting for the device to send an ack with a boolean that could be set to stop the thread because it never leaves the waiting call. This is embedded software so I cannot modify the waiting function. I can only modify the C# interface to the embedded software.