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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:14:19+00:00 2026-05-24T12:14:19+00:00

I have a Windows Form application that involves two Forms. The child form is

  • 0

I have a Windows Form application that involves two Forms. The child form is used to export data into CSV files, and uses a background worker to write the file. While this is occurring I have the form hidden.
The parent form is still active while the background worker is running, so the user can exit the application, even when the background worker is writing files. On the parent form I have added a FormClosing event handler to prompt the user if a background worker is still running.
The problem I am encountering is accessing the background worker in the parent form. Here is what I tried…

    private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
    {
        ExportForm eForm = new ExportForm(GridView, TableName, GridProgressBar, ProgressLabel);

        if (eForm.PartWorker.IsBusy == true)
            MessageBox.Show("Busy");
    }

The problem will this is that it is creating a new instance of the Child Form, so the background worker will never have true for it’s IsBusy attribute. How could I access this background worker in my parent form so I can check to see if this condition is true.

Here is the code for the PartWorker BackgroundWorker…

    #region PartWorker Events

    void PartWorker_DoWork(object sender, DoWorkEventArgs e)
    {
        GetSwitch();
        int batchNum = 0;
        bool done = false;
        ProgressLabel.Visible = true;

        while (!done)
        {
            for (int i = 1; i <= 100; i++)
            {
                Thread.Sleep(100);
                PartWorker.ReportProgress(i);
            }

            done = Export.ExportPartition(SaveFile, DataTable, 50000, batchNum++);
        }
    }

    void PartWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        Progress.Style = ProgressBarStyle.Blocks;
        Progress.Value = e.ProgressPercentage;
        //May want to put the file name that is being written here.
        ProgressLabel.Text = "Writing File: " + e.ProgressPercentage.ToString()  +"% Complete";
    }

    void PartWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
        Progress.Value = 100;
        ProgressLabel.Visible = false;
        Progress.Visible = false;
        MessageBox.Show("Files sucessfully created!", "Files Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
        PartWorker.Dispose();
        this.Close();
    }
    #endregion
  • 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-24T12:14:20+00:00Added an answer on May 24, 2026 at 12:14 pm

    Hold a reference to the child form in the main form:

    class MainForm : Form {
        private ExportForm exportForm;
    
        // assign exportForm wherever the child form is created
    }
    

    Next, in your ExportForm, create a property that indicates that the form is still busy.
    This is a better approach than accessing its BackgroundWorker (read: encapsulation).

    class ExportForm : Form {
        public bool IsBusy {
            get { return this.PartWorker.IsBusy; }
        }
    }
    

    Then do the check in the main form by accessing the newly created property:

    void MainForm_FormClosing(object sender, FormClosingEventArgs e)
    {
        if (this.exportForm.IsBusy)
            MessageBox.Show("Busy");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a windows form application that uses a Shared class to house all
I have a Windows Form application that, when the form is Activated, Deactivated, or
Background : I have a C# Windows Forms application that contains a Windows service
I have been developing a C# windows form application in XP. It all works
I have a Windows Form that takes quite a bit of time to load
I have a simple .NET 2.0 windows form app that runs off of a
I have a method that creates a bound with a windows form and also
I have an ASP.NET web form application that on the server side I need
I am developing a windows form application in C#. I have a datagridview on
I'm using C# and I have windows form and web service... I have a

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.