I have a foreach loop that looks like this:
foreach (var line in theCP4UnknownList.Distinct())
{
var splitUnknowns = line.Split(' ');
KTS_Save saveForm = new KTS_Save(splitUnknowns[0], splitUnknowns[1], splitUnknowns[3], splitUnknowns[4], openFile.FileName);
saveForm.Show();
saveForm.Activate();
//This is where I would like to add a check to see if a button is clicked, if true continue the foreach loop, else wait for the button to be clicked.
}
This KTS_Save form has 4 textbox fields which will be automatically filled every time (as well as other blank ones that need to be filled by the user) the foreach loop starts. However, I only want one new form to be open at a time, thus the program needs to wait for the user to click a “Save” button before the next KTS_Save form is opened…. The save button will save the current data in the form to a text file.
Is there any possible way to pause the foreach loop and wait for a button to be clicked? How can I achieve this?
Just change your code to that: