Hi, Im not sure about your code. But there are ways to detect a
sharing violation (i.e. some other process is still writing the file).
See this: http://www.pcreview.co.uk/forums/thread-1387967.php
Hope it will help you.



Cheers...




On Fri, Mar 13, 2009 at 7:52 PM, Jason <[email protected]> wrote:
>
> Hi,
>
> I need to read a file, that may be open in another process/thread of
> mine (for a short time period), but I have no means of communication
> between the processes/threads so cant pass around locks/mutexs etc...
> So if the file is currently open, I just want to block until it is
> free to use.
>
> If I use this code:
>
> sr = new StreamReader(new FileStream(db_file, FileMode.Open,
> FileAccess.Read));
> TextReader tr = TextReader.Synchronized(sr);
> stationID = Int32.Parse(tr.ReadLine());
> tr.Close();
> sr.Close();
>
> Will that work as I expect? i.e say that code executes at the same
> time in different processes on the same file, will it block until the
> file can be opened and read from?
>
> Thanks alot,
>

Reply via email to