Question

I've written a c# application which is supposed to open a selected file, and read all the lines in it.

The goal is to launch application A and redirect its output to file B, and then, using this new app, read the content of the file B and print it to a ListBox.

The thing is that application A is running 24/7 and writes new outputs to the file B, I would like to catch those new lines in real time, and print them to the ListBox.

Is that even possible? I tried using File.ReadAllLines(filename), but that didn't work saying that the file is in use.

Was it helpful?

Solution

Have you tried this stream-reading solution?

     var reader = new System.IO.FileStream("Path", 
                                                 FileMode.Open, 
                                                 FileAccess.Read, 
                                                 FileShare.ReadWrite);

OTHER TIPS

try this: http://msdn.microsoft.com/en-us/library/aa988006(v=vs.80).aspx
This could resolve the problem of the "File is open".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top