We help IT Professionals succeed at work.
Get Started

C# - Pass long acting function from child form to parent form and add bgworker and progress bar ?

gsdevEE
gsdevEE asked
on
717 Views
Last Modified: 2013-12-17
I have a wizard application that creates/publishes data to SQL server and creates a file - it is very sloppy right now in doing so, and I would like to make it wore elegant by passing all the parameters and functiopns out of the child form where the work is currently being done to the parent form, and I would like to put the offending function in a bd worker and add a progress bar, showing text on what is going on - I have no idea how to do this, and I would think it would be pretty straightforward, but here are the questions I have (I know how to restructur the functions)

1 - How to Close a child form, but before disposing, pass the needed function info into a bg worker on the parent form,. so that the function may now be done there.

2. Tie the function into the bgworker, and add a status bar as the process runs

3.  Show what functions are being completed at what time in the progress bar dialog

I will include the code from bith forms to show what I am talking about

PARENT FORM CALLS CHILD FORM, AND ON RETURNED DIALOG RESULT PROCESSES REMAINING INFORMATION

        private void OpenApplicationWizard()
        {
 
            WizardSheet wizard = new WizardSheet(WebServiceUrl.AbsoluteUri);
           //Here is how the child form is called, perhaps just call Show ?
             DialogResult result = wizard.ShowDialog();
           //THis code gets called after child form closes
            SelectedApplicant = wizard.WelcomePage.SelectedApplicantName;

            if (result == DialogResult.Cancel) return;
            MyDataSet.Merge(wizard.wizardDataSet as DataSet, true);
            Update.UpdateSubmissionLabels(0, MyDataSet);

            _dataManager.SaveApplicationData();
            LoadNewFile("");
        }

CHILD FORM CODE THAT CLOSES WINDOW AND RETURN DIALOG RESULT
//CUSTOM EVENT THAT CLOSES FORM
   private void CompletePage_WizardFinish(object sender, WizardPageEventArgs e)
        {
            try
            {
//CODE THAT WILL BE PUT INTO BGWORKER
                UpdateApplication();
            UpdateApplicant();
                UpdateAgency();
                UpdateProcedure();
                UpdateSubmission();
                UpdateProducts();
//END
//CODE THAT RETURNS DIALOG RESULT
                ParentForm.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {

                StandardMessageBox.ShowMessageBox(this, ex.Message);
           
            }
        }
Comment
Watch Question
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009
Commented:
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE