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.
Path GetTempPath Returns the path of the current user's temporary folder.
The Temporary files created by the Windows operating system are usually stored in the %system%\Windows\Temp folder, whereas the ones created by the User when running any software is stored in his user profile at %userprofiles%\AppData\Local\.
This error has the following cause and solution: The drive that contains the directory specified by the TEMP environment variable is full. Delete files from the full drive or specify a different drive in the TEMP environment variable. The TEMP environment variable specifies an invalid or read-only drive or directory.
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:
The GetTempFileName method will raise an IOException if it is used to create more than 65535 files without deleting previous temporary files.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With