researched many topics about this exception, no luck. my simple code:
string t = Path.GetTempFileName();
t = t.Remove(t.Length - 11, 11);
var q = Directory.EnumerateFiles(t, "tmp????.tmp");
var f = q.ToList();
for (int i = 0; i < q.Count(); i++)
{
// if (Helper.CanReadFile(f[i]))
try
{
File.Delete(f[i]);
}
catch (IOException)
{
break;
}
}
I ran this code in Closing event of mainwindow. So it deletes several files, gets into exception, then to "break" statement, and then.. somewhere. Just freezes and pausing debugger leads to nothing. I tried several pieces of code to find whether the file is used before deletion, but it gets an exception inside this code (like Helper.CanReadFile) and halts program flow there. I dont really have to delete all files, but I need to stop that freezing. How can I work with this exception so that wont freeze my program?
some edit with breakpoints and info for most of them.
1) got an exception https://i.stack.imgur.com/tokgy.jpg
2) first step from it, nothing much https://i.stack.imgur.com/ZBebU.jpg
3) went back to dispose https://i.stack.imgur.com/M04pZ.jpg
4) went back to event method https://i.stack.imgur.com/1sWOv.jpg
5) which was called from onclose https://i.stack.imgur.com/sLe9e.jpg
6) after that it loops here for a while (I use global hotkey) http://imgur.com/a/0qjdf it goes off after ~10 loops with msg = 130. and my program closes fine if I remove file deletion part.
7) Freezed part (no code is running message) http://imgur.com/a/WeEGj