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

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
Try loading this normal .jpg file in Internet Explorer 6.0. I get an error
Try the following code public enum Color { Blue=1, Red=2, Green=3 } public List<Color>
Try running this in a .VBS file MsgBox(545.14-544.94) You get a neat little answer
I have a Winforms application, which hosts two PDF Viewers (Unmanaged C++) in its
I have this database which contains a varchar. I want to know which records
I have a C++/MFC application I need to restructure. The app used to process
I have a div that is divided into two parts. left and right. it
I have see some discussion around this topic and concluded that it is not

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.