c# - How can i check if the file size is larger then it was in the beginning? -


this code:

private void timer2_tick(object sender, eventargs e)         {             timercount += 1;             timercount.text = timespan.fromseconds(timercount).tostring();             timercount.visible = true;             if (file.exists(path.combine(contentdirectory, "msinfo.nfo")))             {                 string filename = path.combine(contentdirectory, "msinfo.nfo");                 fileinfo f = new fileinfo(filename);                 long s1 = f.length;                 if (f.length > s1)                 {                     timer2.enabled = false;                     timer1.enabled = true;                 }             }         } 

once file exist 1.5mb size after minutes file updating 23mb. want check if file larger before stop timer2 , start timer1.

but line: if (f.length > s1) not logical since im doing time long s1 = f.length;

how can check if file larger ?

you can rely on global variable (like 1 using contentdirectory) storing last observed size. sample code:

public partial class form1 : form {     long timercount = 0;     string contentdirectory = "my directory";     long lastsize = 0;     double biggerthanratio = 1.25;     public form1()     {         initializecomponent();     }      private void timer2_tick(object sender, eventargs e)     {         timercount += 1;         timercount.text = timespan.fromseconds(timercount).tostring();         timercount.visible = true;         if (file.exists(path.combine(contentdirectory, "msinfo.nfo")))         {             string filename = path.combine(contentdirectory, "msinfo.nfo");             fileinfo f = new fileinfo(filename);             if (f.length >= biggerthanratio * lastsize && lastsize > 0)             {                 timer2.enabled = false;                 timer1.enabled = true;             }              lastsize = f.length;         }     } } 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -