I've written a little program for myself that I use to read quite large log files (just plain text and numbers) and writing them out in a textbox (notepadish thingy).
I use this method for reading a file and while it does the trick I'm wondering if there's some way to optimize it and if the current file being read is locked out from being written to while reading it (since it's log files that's constantly being updated this is not good for me).
private void ReadFile(string path)
{
using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (StreamReader reader = new StreamReader(file))
{
StringBuilder sb = new StringBuilder();
string r = reader.ReadLine();
while (r != null)
{
sb.Append(r);
sb.Append(Environment.NewLine);
r = reader.ReadLine();
}
textBox.Text = sb.ToString();
reader.Close();
}
}