Link to home
Start Free TrialLog in
Avatar of dbarasch
dbarasch

asked on

Using backgroundworker on built in .NET functions

How can I determine the progress of various built-in functions in .NET.  For example if I want to use the backgroundworker for the GetFiles() function.  How do I do it?

Within the Do_work event for backgroundworker, I list the My.Computer.FileSystem.GetFiles() function, which basically gets all the files in a particular folder.  However, I want to get the progress of where the system is within that function (Getfiles()), not within the Do_work event handler.
Avatar of brawney
brawney
Flag of United States of America image

I don't see how this can be done.  I don't see any Events on the FileSystem or DirectoryInfo classes that would give you any feedback on progress.
Avatar of Mike Tomlinson
If you want more control over the process then write your own manual recursive file searching algorithm...
The GetFiles function simply returns a collection of Strings. Do you want to show the progress while it's building that collection, or when you are looping through the file names?
Avatar of dbarasch
dbarasch

ASKER

Webtubbs,

Yes.  I want to show the progress while its building that collection.  How can I do that?  I can imagine it being impossible.
It's a SEALED function so I'm pretty sure you can't get progress WHILE it's collecting the file names...
If you can get the progress, then that really stinks.  If the user wants to get files throughout the whole drive, that could take a long time and I have no way to show the progress of the search.
If you want to load the whole drive then you should probably do as "Idle Mind" suggested and write your own recursive loop to read in each folder or folder tree and provide progress along the way.  It will be difficult to get an actual percentage progress, but you could report total files or total folders currently loaded this way.

ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial