I have a fairly extensive question about programming that I was hoping someone could answer, or at least point me in the right direction to begin further research.
I'm writing a program in C# which interacts with a user and a source of information. During the program's execution, there are various loops (waiting for and processing user interactions and data changes). At any point during this, though, the data source can have an error (unstable connection to the data).
If this error occurs, I need to pause execution, note the error (and inform the user), then have the program 'go back to the beginning' of it's execution (before the error occurred).
The way I'm doing this now is rather inelegant.
During every loop in the program (and before and after all related functions), it calls a method which checks for a variable (_stop). There is another thread running which monitors the data source, and if an error occurs, it sets _stop = true.
So, if the method sees _stop == true, it sends back 'false', which begins a cascade of 'return false;' through all methods until the program is back at the original loop. It can then wait for the data to become available and resume functioning.
I feel like there must be a more simple and elegant solution to the problem than constantly calling a method to see if it returns false and then returning false all the way through all my loops, but I don't know what it might be (or how to research the problem further).
Do you have any advice for me?