Is there a “standby” in standby / standby mode?

My C # application starts at system startup and must wait for a local instance of SQL Server until it can actually do anything. Right now, I'm just putting off waiting for a server response (I used to get a wait descriptor in the service, but that was unreliable), then launch the main application dialog.

The problem with this, of course, is that the user cannot say that something is happening before the service starts, and because of the equipment we use, it can take up to a minute. So I'm thinking about selecting the "Download / Wait" indicator. The fact is that our project is close to blocking, and a change, such as creating a new class, will cause many headaches - changing an existing file (for example, Program.cs) is much less intrusive than creating a new one. In short: is there a .NET class that is well suited to display (asynchronously, I think) before I start sailing to SQL Server and then delete when it starts responding?

+4
source share
4 answers

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.

+5
source

Here's the .NET wrapper around the standard Windows progress dialog box:

http://www.codeproject.com/KB/shell/iprogressdialognet.aspx

I have not ruined it, but I'm sure there is a flag to make the progress indicator spin. If you want to get really fantasy, you can even crack your own AVI animation and plug it in.

+2
source

As easy as the “Wait ...” dialog, I don’t understand why.

As far as I know, no. There is no stock. It is almost easier to grow your own ... or just turn off the form and call the hourglass cursor. The same idea is just as easy to implement.

+1
source

You might consider working with SQL in BackgroundWorker (in a workflow). This will leave your application responsive.

0
source

All Articles