Re: [ADVANCED-DOTNET] Allow File to Be Renamed While FileStream Open

2007-04-17 Thread Graeme Taylor
Thanks to Efran and Graeme B for solutions proposed. I have implemented as they suggested and works well. Cheers, Graeme === This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com

Re: [ADVANCED-DOTNET] Allow File to Be Renamed While FileStream Open

2007-04-17 Thread Efran Cobisi
Graeme, Please consider you should open a file only when the event handler is called. So, your open and gather logic would be executed, if the change frequency is less than 10 changes per second, less times than the original code sample. Obviously there is some overhead in opening/closing your fi

Re: [ADVANCED-DOTNET] Allow File to Be Renamed While FileStream Open

2007-04-17 Thread Graeme Bradbury
Efran is correct to use the FileSystemWatcher class rather than polling, since you have to close the file to allow it to be renamed anyway you may as well mkae use of the watcher. An example of the tail utility using the FileSystemWatcher class. http://dotnetjunkies.com/WebLog/johnwood/archive/2

Re: [ADVANCED-DOTNET] Allow File to Be Renamed While FileStream Open

2007-04-17 Thread Graeme Bradbury
You could try opening and closing the file within the while loop. That way while your app is sleeping it doesn't have a hold on the file. You'll need to check for BaseStream.Length being smaller than your stored lastMaxOffset when the other app renames the file. C#/PsuedoCode long lastMaxOffset;

Re: [ADVANCED-DOTNET] Allow File to Be Renamed While FileStream Open

2007-04-17 Thread Graeme Taylor
Hi Efran I had considered using the method you suggest. However, I am only interested in the tail (i.e. the new lines written) each time the file is written to. My thinking was that opening the whole file each time would be more of an overhead than maintaining the file handle throught the life o

Re: [ADVANCED-DOTNET] Allow File to Be Renamed While FileStream Open

2007-04-17 Thread Efran Cobisi
Hello Graeme, The example you have posted the link to is not the better way to execute a task whenever a file changes: polling for file changes every 100ms and keeping the file handle open is definitely not the way to go. Instead, I suggest you to take a look at the FileSystemWatcher class [1]; y

[ADVANCED-DOTNET] Allow File to Be Renamed While FileStream Open

2007-04-17 Thread Graeme Taylor
Hi, I am writing an application that will watch log files for certain text patterns appearing (e.g. errors / warnings). So far, I have created an application that picks up new lines and will check them using RegEx (based on CodeProject article http://www.codeproject.com/cs/files/tail.asp). Ho