Background: I have multithreaded application that has one main UI thread and two threads that are super loops that run for the duration of the program. The worker threads basically read in some information and write an output to a Program Logic Controller.
I am running into an issue that I can't repeat when I'm debugging but only happens when the program is compiled and ran as an executable. I know the proper way of dealing with my issue is to find out why this is happening and deal with it. But while I am doing that I was wondering if it was possible to handle this issue in a different way...
Quesiton : My entire worker thread is in a
Try
Catch ex As Exception
Finally
End Try
Is it good practice / and even possible for me to dispose of my worker thread in the catch when it hits an exception and then restart / reinstantiate itself in the finally block?
I would Imagine a response to this might be "No thats not good practice because if you hit the exception mid loop, you will lose all the states of all your objects in your thread and if you restart it it might throw things out of sync."
This isn't actually going to be a problem for me, because all the states of all my objects are updated real time on the PLC, and the very first thing I do when I start my worker thread is read from the PLC to get all the states of all my objects.
The root of my question is, can a thread restart itself in the finally block?