Read Text File and Update it by C# -


i want read text file changing.

but first problem file size large , hangs first time , every second of text file (txt) changing.

is not first time last 50 lines of file called? program not stopped

and easier read , added changing ...

watch files interested in.

static class program {     static long position = 0;      /// <summary>     /// main entry point application.     /// </summary>     [stathread]     static void main()     {         filesystemwatcher watcher = new filesystemwatcher();         watcher.path = system.environment.currentdirectory;         watcher.notifyfilter = notifyfilters.lastwrite;         watcher.filter = "data.txt"; // or *.txt .txt files.         watcher.changed += new filesystemeventhandler(onchanged);         watcher.enableraisingevents = true;          application.enablevisualstyles();         application.setcompatibletextrenderingdefault(false);         application.run(new form1());     }      public static void onchanged(object source, filesystemeventargs e)     {         using (filestream filestream = new filestream("data.txt", filemode.open))         {             // using ron deijkers answer, skip part din't read.             filestream.seek(position, seekorigin.end);              (int = 0; < filestream.length; i++)             {                 filestream.readbyte();             }         }     } } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

c++ - End of file on pipe magic during open -