I am stuck in some strange problem (which I probably lack in knowledge), I present a violating code:
try { f.Delete(); fTemp.MoveTo(f.FullName); Console.WriteLine("INFO: Old file deleted new file moved in > {0}", f.FullName); } catch (IOException ex) { Console.WriteLine("ERROR: Output file has IO exception > {0}", f.FullName); Environment.ExitCode = 1; }
f and fTemp are FileInfo objects. Therefore, if I run this with code where f is the video file playing in the media player, it throws an exception. This works fine and as expected. Now when I close the media player, it deletes the file !? Although my application has long been closed. Even when I close Visual Studio, it still deletes the file when I close the media player. Itβs as if some kind of callback is being configured somewhere to make sure the file is deleted at some point. This rejection of unwanted behavior. But I canβt understand what exactly is going wrong ...
Result so far:
if (!IsFileLocked(f)) { try { f.Delete(); fTemp.MoveTo(f.FullName); Console.WriteLine("INFO: Old file deleted new file moved in > {0}", f.FullName); } catch (IOException ex) { Console.WriteLine("ERROR: Output file has IO exception > {0}", f.FullName); Environment.ExitCode = 1; } catch (UnauthorizedAccessException ex) { Environment.ExitCode = 2; Console.WriteLine("ERROR: Output file is locked > {0}", f.FullName); } } else { Environment.ExitCode = 3; Console.WriteLine("ERROR: Couldn't delete file was locked"); }
I know that I can still do better between Delete and MoveTo, but for now I will use my changes, fractional coding .....
source share