views:

58

answers:

2

Hi,

we run several instances of our program (c#) on a single computer. In each instance our code tries to create "many" temporary files with help of method Path.GetTempFile(). And sometimes, our program fails with exception:

Exception: Access to the path is denied.
StackTrace:    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.Path.GetTempFileName()

I checked temporary folder and didn't find something strange: free disk is enough, number of temporary files is not very big, etc.

I have only one explanation: one instance gets temporary file and opens it, but in the same time, another instance also gets name of the temporary file and tries to open it. If it is correct? If yes, how to solve the issue, if not how to understand what a problem?

UPD: failed on computer with Windows Server 2008 HPC

Thank you, Igor.

+1  A: 

msdn states for the Path class:

Any public static (Shared in Visual Basic) members of this type are thread safe.

Furthermore there are two reasons given for IO exceptions:

  1. The GetTempFileName method will raise an IOException if it is used to create more than 65535 files without deleting previous temporary files.

  2. The GetTempFileName method will raise an IOException if no unique temporary file name is available. To resolve this error, delete all unneeded temporary files.

I'd recommend to check for this conditions (since you explicitly state that you create many temp files).

tanascius
I checked windows temporary folder. I didn't find more than 1000 files in the folder. "Many" in our case it means maybe 200-300 temporary files (totally) when all instances start to work.As I understand "thread safe" is not equivalent to "multi process save". we have several instances (processes, not threads).
constructor