C# Form is unresponsive when scanning for files -


i made program scans trough user selected folder, search mp3 files , wav files calculate total size of these files when doing program unresponsive labels not update or half , window can't dragged.

how fix problem??

link download program : link link virus total : link

edit :

here code checks file size's :

    public string testfilesize(string dir)     {         if (mfile_option_subfolder_checkbox.checked == true)         {             double totalfilesize = 0;              if (mfile_option_mp3_checkbox.checked == true)             {                 string[] files = system.io.directory.getfiles(dir, "*.mp3", searchoption.alldirectories);                 foreach (string filename in files)                 {                     fileinfo fi = new fileinfo(filename);                      double filesize = fi.length;                     totalfilesize += filesize;                 }             }              if (mfile_option_wav_checkbox.checked == true)             {                 string[] files = system.io.directory.getfiles(dir, "*.wav", searchoption.alldirectories);                 foreach (string filename in files)                 {                     fileinfo fi = new fileinfo(filename);                      double filesize = fi.length;                     totalfilesize += filesize;                 }             }              totalfilesize = math.round((totalfilesize / 1024f) / 1024f, 2);             return totalfilesize.tostring() + " mb";         }         else         {             double totalfilesize = 0;              if (mfile_option_mp3_checkbox.checked == true)             {                 string[] files = system.io.directory.getfiles(dir, "*.mp3", searchoption.topdirectoryonly);                 foreach (string filename in files)                 {                     fileinfo fi = new fileinfo(filename);                      double filesize = fi.length;                     totalfilesize += filesize;                 }             }              if (mfile_option_wav_checkbox.checked == true)             {                 string[] files = system.io.directory.getfiles(dir, "*.wav", searchoption.topdirectoryonly);                 foreach (string filename in files)                 {                     fileinfo fi = new fileinfo(filename);                      double filesize = fi.length;                     totalfilesize += filesize;                 }             }              totalfilesize = math.round((totalfilesize / 1024f) / 1024f, 2);             return totalfilesize.tostring() + " mb";         }     } 

this tried them file types shown above ^^

                if (mfile_option_wav_checkbox.checked == true)             {                 backgroundworker bw = new backgroundworker();                 bw.dowork += (s, e) =>                 {                     string[] files = system.io.directory.getfiles(dir, "*.wav", searchoption.topdirectoryonly);                     foreach (string filename in files)                     {                         fileinfo fi = new fileinfo(filename);                          double filesize = fi.length;                         totalfilesize += filesize;                     }                 };                  bw.runworkerasync();             } 

but returns 0 mb how?

you should use backgroundworkerfor this. if supply code better. far can give this:

backgroundworker bw = new backgroundworker(); bw.dowork += (s,e) =>    {       // work    };  bw.runworkerasync(); 

example based on code:

if (mfile_option_wav_checkbox.checked == true)         {             backgroundworker bw = new backgroundworker();             bw.dowork += (s, e) =>             {                 string[] files = system.io.directory.getfiles(dir, "*.wav", searchoption.topdirectoryonly);                 foreach (string filename in files)                 {                     fileinfo fi = new fileinfo(filename);                      double filesize = fi.length;                     totalfilesize += filesize;                 }             };              bw.runworkercompleted += (s,e) =>             {                     //update gui              }              bw.runworkerasync();         } 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -