.net - c# BackgroundWorker and Treeview in winform -


env: c#, vstudio 2013, 4.5 framework, winforms

goal : insert, inside treeview, content of folder (sub folder + files) user can select needed. display progressbar show progress of loading files , folders in treeview.

what i've done far : in goal ...

error: "this backgroundworker busy , cannot run multiple tasks concurrently". error when go use other apps while application running.

my code :

     void backgroundworkertreeview_dowork(object sender, doworkeventargs e)                 {                     var progress = (((float)(int)e.argument / (float)totalfilesintn) * 100);                     var value = (int)math.round((float)progress);                     backgroundworkertreeview.reportprogress(value, e.argument.tostring());                 } void backgroundworkertreeview_progresschanged(object sender, progresschangedeventargs e)                 {                     ststripbarmain.value = e.progresspercentage;                     toolstripstatuslabelprct.text = " loading " + e.userstate + " of " + totalfilesintn;                 } void backgroundworkertreeview_runworkercompleted(object sender, runworkercompletedeventargs e)                 {                     //do code when bgv completes work                 }          private void listdirectory(treeview treeview, string path)                 {                     try                     {                         treeview.nodes.clear();                         if (path != "")                         {                             var rootdirectoryinfo = new directoryinfo(path);                             treeview.nodes.add(createdirectorynode(rootdirectoryinfo, 0));                         }                     }                     catch (exception e)                     {                         txtlog.text = txtlog.text + "[" + datetime.now + "] " + e.message + "\r\n";                     }                 }      private treenode createdirectorynode(directoryinfo directoryinfo, int indice)             {                      var directorynode = new treenode(directoryinfo.name);                     foreach (var directory in directoryinfo.getdirectories())                     {                         if ((directory.attributes & fileattributes.hidden) != fileattributes.hidden)                         {                             directorynode.nodes.add(createdirectorynode(directory, indice));                         }                     }                     foreach (var file in directoryinfo.getfiles())                     {                         if ((isnullorempty(ext)) ||                             (array.indexof(ext, path.getextension(file.name.tolowerinvariant())) >= 0))                         {                             if ((gettriggerevent(file.fullname).contains(txtparamevent.text)) || (txtparamevent.text == ""))                             {                                 indice++;                                 backgroundworkertreeview.runworkerasync(indice);                                 treenode newtn = new treenode();                                 newtn.text = file.name + @"   (" + gettriggerevent(file.fullname) + @")";                                 newtn.name = file.fullname;                                 directorynode.nodes.add(newtn);                                 newtn.tag = "msg";                             }                         }                         application.doevents();                     }                     return directorynode;             } 

thanks help

richard


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -