Share via


Unlock files locked by other processes with C#

Question

Friday, May 29, 2009 7:14 PM

My application needs to make a set of files available to a process. But these files are already locked by other processes. How do i release the locks aquired by other processes? ... Its not known why other processes are not releasing the locks after writing to the files etc. (its a part of a very big application). Is it possible to release the locks obtained by other processes? If yes.. please suggest a solution  

All replies (1)

Friday, May 29, 2009 9:22 PM âś…Answered

 It's not a supported function of Windows or C#. There are ways around it - mostly by creating a remote thread that calls CloseHandle() inside of the process that has the lock on it - here is a small  bit of sample code:

http://www.codeguru.com/cpp/w-p/files/fileio/article.php/c1287

Unfortunately you will have to write a bit of Interop or a C helper program.