how is it possible to interrupt (with a button) a loop during execution without lost of the data that the code is going to writing in an external file?
To be more clear: I wrote a code that do some measurement on a 3D geometry varying some parameter with a for loop.
This loop can goes on for days.
The measurements are writed in an external file.
Now I need to add a button to interrupt the operation without loss of data.
Thanks in advance
Lenovo ThinkPad W540, Win7, 16GB. Developing in: Java | C | KF
Production: NX220.127.116.11 MP11 64bit Testing: NX18.104.22.168
I am still not clear to the question, if you want your data to be executed inside for loop, your loop should execute.
There are ways you can stop loop using break & conditional statements.
I hope to be more clear:
I wrote a code that executes some operations that can continue for days.
So when I click on "RUN" button on the WinForm interface the software starts writing data on an external file and can continue for days.
Now I would like to add a new button on the WinForm to stop the execution, to flush the buffer on and to save the file.
As Stefan said, this should be a new question, so that people who are just browsing through the question titles can find the answers.
The logic should be something like this:
(1) When the user clicks the "stop" button, you set some global variable to indicate this. So, you might have a line of code like "clicked = True" in the function that handles the button's click event.
(2) Then, every time through your loop (or every tenth time, or every few minutes, or something) you check to see if "clicked = True". If it is, you flush the buffer and close the file.
Unfortunately this solution cannot work because the UI freeze and all the button does not work.
I found on internet some solution to release the UI but it seems too complicated.
At the moment I solved with the check if an external file exist.