I have a Windows form and a class with two simple methods that work in a recursively non-deterministic way (which means that it is not known which recursion will be called, and both can cause the other) ... Now there are some points during this recursion, on which I want to pause, and wait for the user to click the "Next Step" button. Only after pressing a button if recursive functions continue. The class runs in a separate thread, so it does not block the user interface.
During this pause, the form simply extracts the value from the class and displays it in the list. Then, after pressing the button, the recursion continues until the next pause (). I need this so that the user can see what happens in the recursion step by step. Also I need to be able to put Pause () anywhere in the recursive method (even several times) without causing any side effects ...
The only way that comes to my mind is to call the Pause () method, in which the loop checks for some blocked flag and then sleeps for a while (the button then sets the flag), but I had some unpleasant impressions from Thread.Sleep () in Windows Forms (UI lock), so I'm considering other options.
Is there any clean way to do this?
source
share