UncleRonin
Well-known member
Righto. I have an app which has a thread running continuously throughout the app's lifetime. When the main form closes the app closes. What is the best way to shutdown this thread?
At the moment, when I start the thread I add it to a collection (ArrayList). When I close the app I cycle through the collection and call .Abort() for all active threads. In the thread i encapsulate all the code in a try catch and catch the exeption thrown when the thread is aborted. There is no special code executed within the thread it just gets the status of various databases and servers.
Is this the right way to go about shutting down my thread or is there a better way (I'm guessing there is >_<) ?
Another question, if in the thread I connect to a db and before it closes the connection the exception is thrown (the Con.Close() is in a nested try catch's finally block). The nested finally should still execute before going to the thread's exception handling block?
At the moment, when I start the thread I add it to a collection (ArrayList). When I close the app I cycle through the collection and call .Abort() for all active threads. In the thread i encapsulate all the code in a try catch and catch the exeption thrown when the thread is aborted. There is no special code executed within the thread it just gets the status of various databases and servers.
Is this the right way to go about shutting down my thread or is there a better way (I'm guessing there is >_<) ?
Another question, if in the thread I connect to a db and before it closes the connection the exception is thrown (the Con.Close() is in a nested try catch's finally block). The nested finally should still execute before going to the thread's exception handling block?