Just sharing some of my inconsequential lunch conversations with you... RSS  

Sunday, April 06, 2008

StringReader sharing issue

I was using my LINQ log retriever collecting some data from a live server when I got an IOException for file sharing. Probably not what I would expect, but it makes sense: by default, FileShare is set to None.

So if all you want to do is just read the damned file, and you're not interested on the fact that this file may be written by another process, all you have to do is:

        StreamReader reader = new StreamReader(
new FileStream(
filename,
FileMode.Open,
FileAccess.Read,
FileShare.ReadWrite
)
)

For log collecting retrieval, this is now my default mode :)

No comments:

Development Catharsis :: Copyright 2006 Mário Romano