Let i have program that open file and append something. If i should run two apllication i will get IOException file used by another process. How it's possible to check that file Log.txt is using by another process?
class Program
{
static void Main(string[] args)
{
FileInfo file = new FileInfo(@"D:\Log.txt");
using (StreamWriter sw = file.AppendText())
{
for (int i = 0; i < 1000; i++)
{
System.Threading.Thread.Sleep(100);
sw.WriteLine("Hello");
sw.WriteLine("And");
sw.WriteLine("Welcome");
}
Console.WriteLine("The work is done");
}
}
}