Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

.Net Form - Pause and Continue or Restart Loop interruptions

Posted on 2013-05-30
2
Medium Priority
?
344 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 2000 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

618 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