All,
For my application, I need to have a progress bar form for a long running data enveloping job/big OpenXML Excel file write, so I have created a "pop-up" form called "RunEnvelope_Form". It is simple and contains a progress bar, status box, cancel button and close button. I am utilizing a Background worker to do the heaving data enveloping/Excel file write work which is working fine.
In order to have the BackgroundWorker.RunWorkerAsync execute automatically I have added it to the end of the Shown event of the RunEnvelope_Form (which
SEEMED like a good idea). The BackgroundWorker executes successfully, but I have a few problems:
[1] The progress window cannot be moved
[2] Most importantly the Cancel button is unresponsive until
after the RunWorkerCompleted event is executed.
Thinking about it, makes sense since I suspect the main form has not entered the message loop yet?
So my question is, what is the best way to start RunWorkerAsync automatically when a form is displayed? I really really want to avoid a start button which seems to be the norm in the examples on MSDN I have come across.
This is how I display the form from my main application window:
DialogResult dr = EnvelopeResults.ShowDialog();
And this is the Shown event in the RunEnvelope_Form form (note all of the Worker thread machinery is setup in the constructor for the form):
private void RunEnvelope_Form_Shown(object sender, EventArgs e)
{
CanceAsyncButton_Click.Enabled = true;
CloseFormOKButton_Click.Enabled = false;
Status_Label.Text = "";
EnvelopeProgress_Bar.Value = 0;
EnvelopeProgress_Bar.Style = ProgressBarStyle.Continuous;
EnvelopeProgress_Bar.ForeColor = Color.Green;
Tuple<AnalysisSeries, Dictionary<int, bool>, string> aysncData =
new Tuple<AnalysisSeries, Dictionary<int, bool>, string>
(_Aseries, _CasestoRender, _OutputXLS);
EnvelopeResults_Worker.RunWorkerAsync(aysncData);
}
Thanks!
What I have tried:
MSDN, Other posts on this site.