C# - Filesystemwatcher to enable Timer -


hello all,

//pleas have simple problem. need, when filesystemwatcher sees file -after fsw start timer closing application (application closed after 2 second, when file created)//

thank user "never quit" *

finaly have "easy" code :-)

 public partial class form1 : form {      system.timers.timer casovac = new system.timers.timer();     int totalseconds = 0;      public form1()     {          initializecomponent();         casovac.interval = 1000;         casovac.elapsed += new system.timers.elapsedeventhandler(cas_elapsed);      }     void cas_elapsed(object sender, system.timers.elapsedeventargs e)     {           totalseconds++;          if (totalseconds == 3)          {             casovac.stop();             application.exit();         }     }      private void form1_load(object sender, eventargs e)     {          filesystemwatcher fsw = new filesystemwatcher();          fsw.path = application.startuppath + "\\out\\";         fsw.filter = "file.exe";         fsw.includesubdirectories = true;         fsw.notifyfilter = notifyfilters.lastaccess | notifyfilters.lastwrite         | notifyfilters.filename | notifyfilters.directoryname;         fsw.changed += new filesystemeventhandler(fsw_changed);         fsw.created += new filesystemeventhandler(fsw_changed);         fsw.enableraisingevents = true;     }     private void fsw_changed(object source, filesystemeventargs e)     {          casovac.start();              }     } 

}

but thank ;-)

i think want create 1 filesystemwatcher monitors specified path , gives event when founds "file.exe". program found file timer started , after several time(2 sec) application closed automatically. right???

i've made demo fulfill requirement.

public partial class form1 : form     {         system.timers.timer tim = new system.timers.timer();         int totalseconds = 0;          public form1()         {             initializecomponent();              tim.interval = 1000; // 1 sec             tim.elapsed += new system.timers.elapsedeventhandler(tim_elapsed);         }          void tim_elapsed(object sender, system.timers.elapsedeventargs e)         {             // .....             totalseconds++;              if (totalseconds == 2) // 2 sec of wait             {                 tim.stop();                 application.exit();             }         }          private void form1_load(object sender, eventargs e)         {             filesystemwatcher fsw = new filesystemwatcher("d:\\");              fsw.includesubdirectories = true;             fsw.filter = "file.exe";              fsw.notifyfilter = notifyfilters.lastaccess | notifyfilters.lastwrite             | notifyfilters.filename | notifyfilters.directoryname;              fsw.changed += new filesystemeventhandler(onchanged);              fsw.created += new filesystemeventhandler(oncreated);              fsw.deleted += new filesystemeventhandler(ondeleted);              fsw.renamed += new renamedeventhandler(onrenamed);                         fsw.enableraisingevents = true;         }            private  void onchanged(object source, filesystemeventargs e)         {             //  show file has been changed              watcherchangetypes wct = e.changetype;                             messagebox.show("onchanged file " + e.fullpath + wct.tostring());                 tim.start();// start timer file.exe found....         }          private void oncreated(object source, filesystemeventargs e)         {             //  show file has been created              watcherchangetypes wct = e.changetype;                             messagebox.show("oncreated file " + e.fullpath + wct.tostring());                 tim.start();// start timer file.exe found....         }          private void ondeleted(object source, filesystemeventargs e)         {             //  show file has been deleted.              watcherchangetypes wct = e.changetype;                            messagebox.show("ondeleted file " + e.fullpath + wct.tostring());                 tim.start();// start timer file.exe found....         }          //  method called when file renamed.          private  void onrenamed(object source, renamedeventargs e)         {             //  show file has been renamed.              watcherchangetypes wct = e.changetype;                            messagebox.show("onrenamed file " + e.oldfullpath + e.fullpath + wct.tostring());                 tim.start(); // start timer file.exe found....         }     } 

hope you....


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -