[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Using backgroundworker on built in .NET functions

Posted on 2009-02-20
9
Medium Priority
?
300 Views
Last Modified: 2013-11-26
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.
0
Comment
Question by:dbarasch
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 4

Expert Comment

by:brawney
ID: 23696864
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.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 23697144
If you want more control over the process then write your own manual recursive file searching algorithm...
0
 
LVL 48

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 23697193
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?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:dbarasch
ID: 23702191
Webtubbs,

Yes.  I want to show the progress while its building that collection.  How can I do that?  I can imagine it being impossible.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 23702304
It's a SEALED function so I'm pretty sure you can't get progress WHILE it's collecting the file names...
0
 

Author Comment

by:dbarasch
ID: 23704793
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.
0
 
LVL 4

Expert Comment

by:brawney
ID: 23705109
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.

0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 23706063
To give a percentage of completion, which is necessary for a progressbar, you FIRST have to know how many items TOTAL are being searched thru and/or returned.

...but the whole point of a search is to find that information in the first place!  Thus this is a chicken and egg problem...

To get a total count we have to recursively visit every folder on the drive (or search path)...something that we don't know how long will take because we only have knowledge of how many files are at the CURRENT level in the folder hierarchy.

The ProgressBar has a Marquee mode, which simply shows that a process is running:
http://msdn.microsoft.com/en-us/library/system.windows.forms.progressbarstyle.aspx

    "Marquee - Indicates progress by continuously scrolling a block across a ProgressBar in a marquee fashion."

This is exactly what the built-in Windows Explorer search does when it wants to report progress during a search.  It doesn't give an exact percentage complete...it just bounces back in forth in "marquee" mode to show that work is being done.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question