I have following code snippet in c# in which I am reading file parallely and replacing some text after reading and then writing back to different location. 
I am not getting any exception but file is not written to different location 

```
class Program
{
    private static readonly object _loc = new object();
    public static string FileRead(string fileName)
    {
        string pattern = @"the";
        var result = File.ReadAllText(fileName);
        var replacedText = Regex.Replace(result, pattern, "XXXX");
        var path = Path.Combine(@"D:\Demo2", fileName);
        using (StreamWriter sw = new StreamWriter(path, false))
            sw.Write(replacedText);
        return replacedText;
    }
    static void Main(string[] args)
    {
        var files = Directory.GetFiles(@"D:\Demo", "*.txt");
        Parallel.ForEach(files, x =>
        {
            Console.WriteLine("FileName={0}\tNOC={1}",x, FileRead(x).Length);
        });
        Console.ReadLine();
    }
}

```