954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C# Progress Bar and Listbox

Hey,

I'm having a bit of trouble with progress bars and background workers and want to try and solve this with the simplest solution

What I am doing is reading the contents of a specific directory, I am then displaying in a list box all the folder names so that a user can click on them for further functionality

What I want to do, Is have a progress bar run whilst it is adding the folders to the list box but I am not sure how I can do it..

Is anyone able to help me out?

Thanks

Dan
_____
C# - Visual Studio 2010

D.Twomey
Newbie Poster
4 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

Calculating how many files are in a directory structure (the max of the progress bar) would take pretty much just as much time as loading in the directory structure (which isn't very long with System.IO.Directory.GetDirectories()).

Basically the time it takes to count the directories is almost identical to loading all of the directory strings into an array. So unless you want this operation to take twice as long, I would just use a Marquee progress bar to let the user know the pc is busy. How are you loading in these directory names?

skatamatic
Posting Shark
959 posts since Nov 2007
Reputation Points: 403
Solved Threads: 129
 

If there is a loop and you try to change ProgressBar value from this loop you have to check is your ProgressBar in the same thread of loop is working. (Use InvokeRequired and if it is true Invoke the method)

I recommend you dont change the value of a ProgressBar or any other controls within a thread. Instead rise an custom event.

VatooVatoo
Light Poster
44 posts since Jan 2007
Reputation Points: 20
Solved Threads: 2
 

Try pInvoke and FindFirst/FindNext for adding files into list.

NetDeveloper
Newbie Poster
5 posts since Feb 2012
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: