I want to make the program wait for a button to be pressed before it continues, I tried creating a while loop and having it loop until the button is clicked and sets a bool
Windows Forms Controls have a Click event you can subscribe to in the form constructor:
myButton.Click += myButton_EventHandler;
You can then put whatever logic you want to happen in the handler and this will execute when the button has been clicked:
private void myButton_EventHandler(object sender, EventArgs e)
{
Redpress = false;
}
You should avoid blocking (in any way, spinning sleeping etc) the Main thread in your forms applications as this will lock up the interface, there are many methods to avoid this including Timers, Threads, Delegates and BackgroundWorkers to name a few.
EDIT: To include your update
For this you could use a ManualResetEvent
.
private readonly ManualResetEvent mre = new ManualResetEvent(false);
private void myButton_EventHandler(object sender, EventArgs e)
{
mre.Set();
}
Your Form code can wait by calling:
mre.WaitOne();
This will make the executing code wait until the event has fired. Hope that helps.
NOTE: Please don't be mistaken though, unless you have some special case (I can't think of one off the top of my head at this time of night!) you should put the code straight in the event handler, rather than blocking a thread until the event has fired.