C# Sharing file handles across threads
<p>I have a piece of code that is executed by <code>n</code> threads. The code contains,</p>

<pre><code>for(;;)//repeat about 10,000 times
{
    lock(padlock)
    {
        File.AppendAllText(fileName, text);
    }
}
</code></pre>

<p>Basically, all threads write to the same set of 10,000 files and hence the files are the shared resource. The issue is that the 10,000 open,write,close performed by each thread is slowing down my program considerably. If I could share the file handlers across threads, I'd be able to keep them open and write from different threads. Can someone throw some light on how I can proceed?</p>
