Solved

.Net Form - Pause and Continue or Restart Loop interruptions

Posted on 2013-05-30
2
336 Views
Last Modified: 2013-05-30
Hello, I have a .Net Form application.
When a "Run" button is clicked it does some Big Loop and constantly updates the GUI.
In case during this loop the user checks a CheckBox
the loop should be halted (so the user can examine the details displayed a TextBox).
Afterwards, the user can click a Continue or Restart button.
How should I program that?
here is a code skeleton.
    //
    foreach (Object o in SomeBigList)
    {
        //
        // do some calculations withe the object and update a TextBox.
        //
        Application.DoEvents();
        if (StopCheckBox.Checked)
        {
            // Pause the Loop and wait for further GUI operation - Continue or Run Again.
        }
    }
    //

private void ContinueButton_Click(object sender, EventArgs e)
{
    // Continue running the Loop.
}

private void RunButton_Click(object sender, EventArgs e)
{
    // If the Loop is Paused then Exit from the Loop.
    // Run again.
}

Open in new window

Thanks, Aryeh.
0
Comment
Question by:tuchfeld
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 39209416
Move the loop to a background thread using a BackgroundWorker() control, then pause/resume it using a ManualResetEvent and a boolean flag.
0
 

Author Comment

by:tuchfeld
ID: 39209602
Thanks!
BTW: I also used:
this.Invoke(new MethodInvoker(delegate { textBox2.Text = "hello world"; }));

Open in new window

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now