Greetings. Actually, this question interests: "How to find out how the file is busy?" Can this be implemented using FileSystemWatcher ?

    1 answer 1

    On SO, they propose to use the handle.exe utility and kill the process in the following way:

    string fileName = @"c:\aaa.doc"; //Путь к занятому файлу Process tool = new Process(); tool.StartInfo.FileName = "handle.exe"; tool.StartInfo.Arguments = fileName+" /accepteula"; tool.StartInfo.UseShellExecute = false; tool.StartInfo.RedirectStandardOutput = true; tool.Start(); tool.WaitForExit(); string outputTool = tool.StandardOutput.ReadToEnd(); string matchPattern = @"(?<=\s+pid:\s+)\b(\d+)\b(?=\s+)"; foreach(Match match in Regex.Matches(outputTool, matchPattern)) { Process.GetProcessById(int.Parse(match.Value)).Kill(); } 

    But there is also a hyper-variant : the listing on PasteBin , which also shows the process that occupied the file.

    • Thanks, I just needed the option without extraneous programs) - Sharp