Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C# (http://www.programmingforums.org/forum16.html)
-   -   Windows Forms: Timers / Progress Bar help needed. (http://www.programmingforums.org/showthread.php?t=15140)

BstrucT Feb 8th, 2008 12:20 AM

Windows Forms: Timers / Progress Bar help needed.
 
Hi to all out there!

I have recently made somewhat a transition into the world of C# and have worked through quite a few tutorials by now and started playing with windows forms.

I wrote a little data capturing application that takes various user inputs and display them all on a text file to preview, from where the user can save the text file.

I would like insert a progress bar for when another form is opened, or when data is being saved, do I need to use a timer?

If so does anyone know of links that I can read up on the subject?

I've looked around but to no avail.
Thanks

>>BstrucT

Dameon Feb 8th, 2008 10:20 PM

Re: Windows Forms: Timers / Progress Bar help needed.
 
The progress bar will probably have very little time to display/be useful for opening forms/saving text files. Such operations are typically near instant except for large amounts of data.

Look in to the BackgroundWorker component. It is essentially a thread, nicely wrapped up to allow progress reporting, cancellation, etc. This means that your program will be in "two places" at once - multitasking within your program just as you can have multiple programs running at one time. The form will continue to be responsive while saving, etc occurs in the background. The progress bar can be updated as needed (note: limit number of progress updates to something reasonable). Threading introduces certain difficulties, but if you use BackgroundWorker as it is intended, most are avoided altogether.

BackgroundWorker is not suitable for opening a new form. This has to be done on the main thread (the only one allowed to touch windows forms-related stuff). However, creating a form takes an insignificant amount of time. What may take time is loading the data to be displayed. That's what you may need to put in the background.

BstrucT Feb 11th, 2008 2:55 AM

Re: Windows Forms: Timers / Progress Bar help needed.
 
Thanks man, have just printed off some docs on the background worker and will start checking it out.

I see now that the progress bar is dependant on data being handled by the backgound worker in a way, will revert if I encounter any problems.

Thanks for the advice.


All times are GMT -5. The time now is 7:45 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC