Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
The process cannot access the file
Message
 
To
30/09/2008 01:22:38
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 8.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01351711
Message ID:
01351758
Views:
18
>In a CRC32() class, I need to read a file by the use of FileStream() in such an approach:
>
>
>        ' This is the main method to call
>        Public Function GetCRC() As Boolean
>            Dim loStream As Stream
>            loStream = New FileStream(cFileName, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
>            nCRC32 = GetCrc32(loStream)
>            loStream.Close()
>            Return True
>        End Function
>
>
>However, occasionnaly, the FileStream() method cannot access the file. It returns this message:
>
>"The process cannot access the file ... because it is being used by another process."
>
>Is there any way to avoid that? Or, is there a way to read the file even if it is being used by another process? Because, even if I implement a retry mechanism, I am not sure in such a context if that would work.

How is the file being created? If you're creating it, make sure you're explicitly closing it as well. How is this code being triggered?

Also, I'd suggest putting the Close() in a Finally section of a Try/Catch.
-Paul

RCS Solutions, Inc.
Blog
Twitter
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform