开发者

Path.GetTempFileName in MultiProcessing

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 temporar开发者_如何学Goy 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.


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).


see http://support.microsoft.com/kb/982613/en-us

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜