0

I cannot think of the best way to achieve this, what I'm trying to do is make my foreach loop stop until a button is clicked, once the button is clicked we then move on to the next value in the foreach loop.

Foreach:

foreach (string site in sites)
{
    Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);
    browser = new ChromiumWebBrowser(site);
    browser.AddressChanged += OnBrowserAddressChanged;
    panelBrowserMain.Controls.Add(browser);
    browser.Dock = DockStyle.Fill;
    browserMain.Text = site;

    // PAUSE HERE UNTIL WE DO WORK IN THE BROWSER, THEN ONCE "NEXT" IS PRESSED MOVE ON TO THE NEXT URL UNTILL THERE IS NO MORE TO PROCESS //                
}

I'm thinking set a bool to false, then await a method (which will return true, so we can move on) then set it to false again (once looped) would this be the best way to go about this, or is there a better way?

logosapp
  • 21
  • 5
  • 4
    Then, why use a loop, to begin with? You could just take the next item of the collection whenever the button is clicked. This can be achieved in a number of ways (track the index, use a queue,...). – 41686d6564 stands w. Palestine Aug 23 '21 at 17:30
  • Agreed. A loop like this is not meant to interact with a system event. You need to set up a list and a pointer that is accessible by the system when button is clicked. When it is clicked, the item that is being pointed at is evaluated and the pointer advanced. – Matt Small Aug 23 '21 at 18:29

0 Answers0