views:

240

answers:

4

I need to show some sort of animation, while windows form application is processing data till it gives a output. Ones the processing completes the animation will stop. There are great tools for this in Dev express for web based apps. But do we have anything similar in windows form applications?

Thanks

This is a windows form calling a stored proc. The SQL query takes about 10mins, I need to run some animation telling system is still processing.Progress bar wont work since I cant assign steps.

A: 

You will want to take a look at the BackgroundWorker class, it will allow you to launch your code on another thread, and handle the communication between the worker thread and the UI thread so that you may update the UI appropriately.

casperOne
Thanks, The link talks about exactly the problem I have. Two threads seems to be the only way
LSB
@LSB: No problem.
casperOne
Got it working perfectly!
LSB
A: 

I'd recommend delegating the work to a BackgroundWorker and showing a progress bar. Since you can't assign steps, you could just use the bar to reflect the amount of time it SHOULD take.

If you wanted to make the progress bar more accurate than just arbitrarily deciding it should take 10 minutes based on tests on your development machine, you could log how long the transaction takes and use the amount of time the transaction most recently took to decide how long your progress bar should take to fill up.

You could also delegate to a BackgroundWorker and show a message with a counter or something in the foreground -- "Query in progress. Time elapsed: 2 minutes. Estimated time to completion: 10 minutes." And then also have a cancel button. Something like that.

Just different possibilities. None are great, but your lack of inside access to the process limits your options.

< edit > oh, it looks like you already got an answer. ah well! < /edit >

Joshua Evensen
BackgroundWorker seems to be the best bet. Setting a fix time is not gonna work as the database grows the query time will also grow.Thanks
LSB
Right, but keeping track of the time each one takes and using that as your estimated time as I suggested above would be helpful in that case, no?
Joshua Evensen
but everytime time increases I will have to change code right?
LSB
what? No. You'd just record the amount of time it takes and save it somewhere, then load the value in at the beginning of a transaction. Why would you have to do it manually?if (File.Exists(SaveFilePath)) ExpectedTime = TimeSpan.Parse(File.ReadAllText(SaveFilePath)); worker.RunWorkerAsync(() => { startTime = DateTime.Now; DoSQLTransaction(); transactionTime = DateTime.Now - start; }); //while the above is running, update progress bar at set intervals //and wait on the operation to complete File.WriteAllText(SaveFilePath, transactionTime.ToString());
Joshua Evensen
A: 

I'd suggest you look at the marque style progress bar in MSDN. It just goes back and forth during your operation. Your SQL query won't have callacks or anything so this would allow you to just indicate that your application is "working" on something.

http://msdn.microsoft.com/en-us/library/bb760816%28VS.85%29.aspx

By creating the progress bar control with the PBS_MARQUEE style, you can animate it in a way that shows activity but does not indicate what proportion of the task is complete. The highlighted part of the progress bar moves repeatedly along the length of the bar. You can start and stop the animation, and control its speed, by sending the PBM_SETMARQUEE message. Marquee progress bars do not have a range or position.

Dave White
A: 

I do this type of thing with a ProgressBar in a separate Form on a seperate Thread. You can use a timer to set ticks every 10 seconds or something, and then just reset the ProgressBar to zero if you need to and have it continue scrolling.

Jess