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 4620736
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:36:02+00:00 2026-05-22T02:36:02+00:00

I try to achieve this: i have the main form, when user click the

  • 0

I try to achieve this:
i have the main form, when user click the red cross on the top right to exit the application, it popup a progress bar form indicating the application is updating/saving information. After the background worker in the progress bar form finishes, it closes the progress bar form and close the main form as well.
the problem i have is, it closes the main from first without even running the background worker. how to fix this? i tried to use e.cancel= true it just gave my dead loop.

here is my main form:

 private static void mainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
 UpdatingForm pbar = new UpdatingForm ();


            pbar.Show();
}

in my updatingform:

public UpdatingForm()
        {
            InitializeComponent();

            bgWorker.RunWorkerAsync();
        }

    private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
            {
    ....
    }

private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {

            this.Close();
            // Application.Exit();
        }
  • 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-05-22T02:36:03+00:00Added an answer on May 22, 2026 at 2:36 am

    Setting e.Cancel to true is correct. However, once your UpdatingForm closes, Application.Exit() fires the mainForm_FormClosing() event again, so you get one more UpdatingForm etc.

    private static bool isClosing = false;
    private static void mainForm_FormClosing(object sender, FormClosingEventArgs e)
    {
        if (!isClosing)
        {
            isClosing = true;
            e.Cancel = true;
            UpdatingForm pbar = new UpdatingForm ();
            pbar.Show();
        }
    }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try that a User can be member of several associations. To achieve this
After failing to achieve this with link_to remote, I decided to try jQuery way.
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
Try this piece of code - public class WhitespaceTest { public static void main(String[]
In my main page I have included a template with form for adding emails
I have this extremely simple splash page here: http://iph0wnz.com It has the main graphic
I'll try to describe the situation I'm having problems with: I have one main
I'm trying to achieve the following with a bash script: try for SSH connection,
try { if (myBoolean) { while (true) ; } else { System.exit(1); } }
try: recursive_function() except RuntimeError e: # is this a max. recursion depth exceeded exception?

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.