Here's a triple threaded version that I hacked together quickly that will do the trick. This can be dropped in anywhere in a visible form (or could be modified for program.cs) and will spawn a new, centered, modal dialog box with a smooth scrolling progress bar that will dominate user attention until FinishedProcessing in the parent thread is set to true.
//Update to true when finished loading or processing
bool FinishedProcessing = false;
System.Threading.AutoResetEvent DialogLoadedFlag
= new System.Threading.AutoResetEvent(false);
(new System.Threading.Thread(()=> {
Form StockWaitForm = new Form()
{ Name = "StockWaitForm", Text = "Please Wait...", ControlBox = false,
FormBorderStyle = FormBorderStyle.FixedDialog, StartPosition = FormStartPosition.CenterParent,
Width = 240, Height = 80, Enabled = true };
ProgressBar ScrollingBar = new ProgressBar()
{ Style = ProgressBarStyle.Marquee, Parent = StockWaitForm,
Dock = DockStyle.Fill, Enabled = true };
StockWaitForm.Load += new EventHandler((x, y) =>
{
DialogLoadedFlag.Set();
(new System.Threading.Thread(()=> {
while (FinishedProcessing == false) Application.DoEvents();
StockWaitForm.Invoke((MethodInvoker)(()=> StockWaitForm.Close()));
})).Start();
});
this.Invoke((MethodInvoker)(()=>StockWaitForm.ShowDialog(this)));
})).Start();
while (DialogLoadedFlag.WaitOne(100,true) == false) Application.DoEvents();
//
//Example Usage
//Faux Work - Have your local SQL server instance load here
for (int x = 0; x < 1000000; x++) int y = x + 2;
FinishedProcessing = true;
Customize to taste. Also, if you do use this in a production app, wrap the new thread contents in try...catch blocks to CYA. One last thing, I'm releasing this code to you under the "Coderer Public License / SO v1.1", as follows:
Coderer Public License / SO v1.0
I, Person known "Coderer" on the community "Stack Overflow", agree to thoroughly consider switching to a sane project management methodology that allows extra classes to be added to projects in the Executing phase. I understand that nazi-like change control is unhealthy for all parties involved.