简体   繁体   中英

Close file left open vb.net?

Hi there how is it going?! I was looking for a way to close / unlock / rename a file that's in use by a process withouth killing that process in vb.net?!

Example: I need to update some .bpl which may be used when i start my update. To do that i try to delete the file or move it (or whatever allows me to put the new .bpl into the folder).

Clearly if the file is in use i get an exception which says that the access to that file is denied because the file is in use by another process. Assuming that i can't shut down the entire process, is there any way to achieve it from vb.net instead of using Handle.exe ?

After many attemps i realize that windows doesn't allow you to close (or do any other task) a file which is actually locked by another process. Suddenly i remembered of a strange behavior that afflicts services .exe (like service_name.exe files).

The behavior i'm talking about regards the chance of renaming the file even if the file is being used by another process. I found out that You can apply the same concept to some files like .bpl files so here's the solution.

I really hope it helps, thansk.

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