c# - BackgroundWorker calling Directory.EnumerateFiles completes before enumeration finishes -


a trivial issue seems.

i have following code snippet. seems completed event fires before enumeratefiles finishes. example, if tb_source.text ... path c:\users\<user>\desktop set folder hundred or items, works , reference.throttler_numer_of_files correctly populated.

it looks though if set say, c:\users\<user> never gets chance find before moving on completed event. perhaps encounters exception when trying count files?

suggesetions?

// count number of files within source directory (and within subdirectories) backgroundworker bw = new backgroundworker(); bw.workerreportsprogress = true;  bw.dowork += new doworkeventhandler(     delegate(object o, doworkeventargs args)     {         thread.sleep(2000); // give current ui moment load         reference.throttler_number_of_files = directory.enumeratefiles(tb_source.text, "*.*", searchoption.alldirectories).count();     } );  bw.runworkercompleted += new runworkercompletedeventhandler(     delegate(object o, runworkercompletedeventargs args)     {         // success, clear launch!         form_throttler_copy throttler_copy = new form_throttler_copy();         throttler_copy.show();         this.dispose();     } );  label_status.text = "creating manifest of files... please wait"; picturebox_loading.visible = true;  bw.runworkerasync(); 

turns out issue there exception (access denied) error during enumeratefiles. i'm able catch exception must determine way can continue enumeration, making move on next file/directory.

edit - future reference, details here helpful on how above: directory.enumeratefiles => unauthorizedaccessexception


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -