0

I have an application where we replace an "artproj" file for our application by writing changes to a separate file and then removing the original file and renaming the new one. It generally works well, but sometimes, it gets "stuck" on the delete, going nowhere, with no option to abort the call within Visual Studio when debugging. Looking at Process Explorer, it looks like my application has a handle on the file at that point, but so does explorer.exe. In fact, when I exit the application, explorer.exe still has three handles on it with the same process ID. I can only guess that's why the delete, which uses FileInfo.Delete, doesn't go through.

Here is the deletion procedure:

private static Exception InternalSafeKill(FileInfo TargetFile)
{
    try
    {
        TargetFile.Attributes = FileAttributes.Normal;
        TargetFile.Delete();
        return null;
    }
    catch (Exception ex)
    {
        return ex;
    }
}

Is there any way to avoid this sort of conflict? To detect it before the call? To safely escape it in some way when detected?

Sean Duggan
  • 1,105
  • 2
  • 18
  • 48
  • Are you using Windows 7? Then it could be `Application Experience`, see https://stackoverflow.com/a/4558420/7556646 – Wollmich Oct 04 '17 at 14:04
  • @Wollmich: Windows 10, actually, although we've had people see this on Windows 7 and Windows 10 (more often with the Home edition). This is one of the first times I've seen it on my dev machine. – Sean Duggan Oct 04 '17 at 14:22

0 Answers0