Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8650467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:49:48+00:00 2026-06-12T13:49:48+00:00

I have a following form Form3 that is opened by another form Form1, and

  • 0

I have a following form Form3 that is opened by another form Form1, and when closed Form1 opens back up.

The problem is when I close Form3 DoSomething keeps running after form is closed.

I understand that I can make DoSomething into a thread and set IsBackground = true but is there another way to stop all processes when form closes.

This code is just example, For illustration.

   public partial class Form3 : Form
    {

    public Form3()
    {
        InitializeComponent();
    }
    private void DoSomething()
    {
        int i = 0;
        while(true)
        {
            if (!this.IsDisposed)
            {
                Application.DoEvents();
                i++;
                Thread.Sleep(10);
                label1.Text = i.ToString();
                dataGridView1.Rows.Add();
            }
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        DoSomething();
    }

    private void Form3_FormClosed(object sender, FormClosedEventArgs e)
    {
        this.Dispose();
        Form1.Default.Show();
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:49:49+00:00Added an answer on June 12, 2026 at 1:49 pm

    Thanks to cdhowie suggestions and input of all others. Mowing DoEvents to the end and adding IsDipsosed solved my problem.

    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }
        private void DoSomething()
        {
            int i = 0;
            while ((true) && !this.IsDisposed)
            {
                    i++;
                    Thread.Sleep(10);
                    label1.Text = i.ToString();
                    dataGridView1.Rows.Add();
                    Application.DoEvents();
            }
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
            DoSomething();
        }
    
        private void Form3_FormClosed(object sender, FormClosedEventArgs e)
        {
            Form1.Default.Show();
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a following problem, I have HTML form that uploads a file with
I have XML in the following form that I want to parse with PHP
I have the following paint event (form) that is drawing the rectangle: void LogicSimulationViewerForm_Paint(object
I have the following form in a Struts2 JSP that contains some radio buttons.
I'm looking at some Java classes that have the following form: public abstract class
i have the following if-clause: if(empty($var)){ $errors[]=Failure; } this is for a form that
I have a form that takes the following inputs: Name: IBM Surface(in m^2): 9
I have a simple html form that looks like the following <form action=search.php method=get>
I have the following mark up of a div that contains a form. The
Lets say that you have a following simple application: <form action=helloServlet method=post> Give name:<input

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.