c# - explorer.exe memory usage is high when deleting files -


i have application running on server.

i start off thread goes infinite loop.

the 1st thing loop enumerate directories in folder.

this folder has many sub-folder receives small image files many clients.

my loop looks directories/files older 24hrs today's immediate time /date.

if older code deletes files , parent folder.

my loop 'sleep' 60 seconds before repeating again.

now, have noticed if there large number of files delete or/and app has been running several days explorer.exe memory increases significantly.

so, have question code.

this code:

thread tharchiver = null; private void btnarchiver_click(object sender, eventargs e) {     try     {         if (btnarchiver.text == "start")         {             btnarchiver.text = "stop";             lvwservices.items[4].subitems[1].text = "started";             tharchiver = new thread(archiveworker);             tharchiver.start();         }         else         {             btnarchiver.text = "start";             lvwservices.items[4].subitems[1].text = "stopped";             tharchiver.abort();          }      }     catch { } }   private void archiveworker()  {      while (true)      {          try          {              list<string> catdirs = directory.enumeratedirectories(cataloguepath, "*", searchoption.topdirectoryonly).tolist();              (int index = 0; index < catdirs.count; index++)              {                  //look @ time of creation , delete directory                  directory.delete(catdirs[index]);              }          }                               catch (exception _ex)          {           //report error          }          thread.sleep(60000);      }  } 

this possible!

reasons can thread sleeps 60 sec only

list<string> catdirs = directory.enumeratedirectories(cataloguepath, "*", searchoption.topdirectoryonly).tolist(); 

and creating list in every new thread happening list of folders , reference stored again , again. , never ending process keep going on , on , size increases. stored in memory see lag.

what suggest is: don't open new thread , put check last thread completed or not.

update: possible reason per comments @andrew , @maarten

list<string> catdirs = directory.enumeratedirectories(cataloguepath, "*", searchoption.topdirectoryonly).tolist();              (int index = 0; index < catdirs.count; index++)              {                  //look @ time of creation , delete directory                  directory.delete(catdirs[index]);              } 

i feel forloop taking time because might happening directory.delete(catdirs[index]); starts new thread no might happening there lot of files deleted in queue , queue increases day day. thats might reason seeing lag


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -