简体   繁体   中英

File.Move locked by a process

We have a web application which does something. As a sub part of that something, pdf files are moved from a folder in machine1 to a folder in machine2. There is a 3rd party software which watches for pdf files on that folder in machine2. We use simple File.Move in a try catch block. This process has been working perfectly all this while. Suddenly the 3rd party is now complaining that they cannot process the pdf because its locked.

Does this mean that the web app when moving the pdf from machine1 to machine2 is holding a lock? File.move is working fine and its not going into catch block. This means the move worked fine.

Do I need to do something in the web app for it to release the lock (if its holding by any chance)?

Thank you.

From what you describe it sounds like you need to call

Dispose()

Are you doing anything else with the PDF that could be holding a lock?

[EDIT] Indeed there is no File.Dispose() method there.

Perhaps your monitoring software is checking for the new file before the copying has finished, (your pdf was particularly large), in which case see this post: File.Move locks file in destination folder?

It's a guess, but it's happened to me many, many times. Check to make sure that someone hasn't installed a virus scanner or something similar that is now monitoring that folder and creating the lock.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM