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
Solved

.Net Form - Pause and Continue or Restart Loop interruptions

Posted on 2013-05-30
2
339 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

808 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