Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

Error: the file is being used by another process

$
0
0

Hi All, 

Here is an application, there are three threads. And each thread contains a function as below to write the same file:

Using(StreamWriter log = File.AppendText(filePathandName)))
{
}

The first two threads are running normally, but the third thread will throw an exception occasionally at using(…).

The exception message: The process cannot access the file ‘filePathandName’ because it is being used by another process.

There is a lock in every thread, so I believe that these three threads have no conflicts. In another word, the first thread opens and writes the file, and then release the file. And then the second thread opens and writes the same file, release the file. But third thread fails to open the same file.

After sleep about 0.5 second in the third thread, the third thread can open the file and write it again. 

How to explain this issue?

Thanks

Scott


Viewing all articles
Browse latest Browse all 1710

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>