File Access Locked Request

Jun 18, 2009 at 3:59 PM

Can the error message "The process cannot access the file because another process has locked a portion of the file." be changed to include the filename?

i.e.- The process cannot access the file <filename.123> because another process has locked a portion of the file."

I guess if there was a way to know the file that is unaccessible it can help troubleshoot.

Coordinator
Jun 18, 2009 at 9:54 PM

Yes, I'm changing the error message to document this.

The original error message - "The process cannot access the file because another process has locked a portion of the file."  - is something that comes from Windows.  I will add to that message, the filename and offset.

Jun 19, 2009 at 1:56 PM

Does 1.8.3.29 included this error message change?

Coordinator
Jun 19, 2009 at 3:07 PM

yes.

Jun 19, 2009 at 7:18 PM

Works like a charm.

Coordinator
Jun 19, 2009 at 9:02 PM

Hey Jeff, have you gotten this error?  "The process cannot access the file because another process has locked a portion of the file."  ?

What file?

And when you say "works like a charm" - what results do you get with 1.8.3.29?  

Jun 19, 2009 at 9:10 PM

I suppose I could have been more clear! :)

I deliberately deleted a file from the directory after the initial processing of the directory but before it could be archived so I could see the error message. I have error messages and stack trace going to a log file in the root of C. An example:

6/19/2009 4:07:44 PM
Could not find file 'C:\Users\jeffy.SELLETHICS\Documents\A_Demo.pst'.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileInfo.get_Length()
   at Ionic.Zip.ZipEntry.FigureCompressionMethodForWriting(Int32 cycle)
   at Ionic.Zip.ZipEntry.WriteHeader(Stream s, Int32 cycle)
   at Ionic.Zip.ZipEntry.Write(Stream s)
   at Ionic.Zip.ZipFile.Save()
   at Ionic.Zip.ZipFile.Save(String zipFileName)
   at SMG_Backup.MainForm.ZipSave(String SourceFolder, String DestFile)

As you can see, it tells me which file it had issue with. This is significant to me as it helps troubleshoot more specifically if there is an issue.

Coordinator
Jun 20, 2009 at 3:26 AM

ok, I See.  now some more info for you.  The error in question, with the specific error message, "The process cannot access the file because another process has locked a portion of the file."  - is something that comes from Windows when another process locks a portion of the file.   What you did was not the same.  It produced an error condition, but a different one than what we were discussing. 

The way to lock a portion of a file in .NET is to call FileSystem.Lock on the file.   If you want to reproduce the error in question, rather than delete the file, take a lock on a portion of the file, with that API.