Solved

.Net Form - Pause and Continue or Restart Loop interruptions

Posted on 2013-05-30
2
342 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

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

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

695 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