c# - TextFile Reader and FileSystemWatcher in Windows Service -
I am trying to read a text file to use FileSystemWatcher such as anything in the Windows service textfile Now I have to face the problem as I should give my FileSystemWatcher code so that I can be called soon as a text file. Do I need to add it to the This is my code structure. Please help me. Thank you .. Updated code .. Do I need to add it to Ostert () yes. However, for this purpose, the thread will be removed once in the thread pool once the OnStart () Windows Service method or anywhere.
Protected override zero on start (string [] args) {_thread = new thread (startReadingTextFile); _thread.Start (); } Public Zero StartTextTextFile () {_freader = New Added Content Reader (TextFile Location); } Private Zero Watcher_Changed (Object Sender, FileSystemEventArgs e) {string addedContent = _freader.GetAddedLines ();
Protected override zero on start (string [] args) {IfLllReadOffset == 0} {_freader = New Added Content Reader (TextFile Location); } // If you saved the last position, when the application was closed, you can use the following // to start from that place like- // freader = new AddContentReader ("E : \\ tmp \\ test.txt ", lastReadPosition); Else {_freader = New Added Dentant Reader (TextFile Location, Last Line Readoffs); } FileSystemWatcher Watcher = New FileSystemWatcher ("C: \\ temp"); Watcher.EnableRaisingEvents = true; Watcher.Changed + = New FileSystemEventHandler (Watcher_Changed); } Private Zero Watcher_Changed (Object Sender, FileSystemEventArgs e) {string addedContent = _freader.GetAddedLines (); // you (stringreader reader = new string reader) {string line; ({Line = reader. Readline ()) = tap) {// processing function call}}}
FileSystemWatcher.config enabled events are set: You
OnStart .
Comments
Post a Comment