Here is a triple streaming version that I quickly hacked to do the trick. This can be dropped anywhere in visible form (or can be changed for program.cs) and create a new, centered modal dialog box with a smooth scrollbar that will dominate the user's attention until FinishedProcessing is set in the parent thread 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 use this in a production application, wrap the new contents of the stream in try ... catch blocks to CYA . The last thing I release this code for you is in the section "Coderer / SO v1.1 Public License", namely:
Coderer Public License / SO v1.0
I, a person known as the Coder in the Stack Overflow community, agree to carefully consider moving to a sound project management methodology that allows you to add additional classes to projects at the Progress stage. I understand that control of Nazi change is unhealthy for all parties involved.
source share