Vatech
Member
- Joined
- Mar 27, 2022
- Messages
- 6
- Programming Experience
- 3-5
I have a folder with about 150 files ( pictures about 150kb each), and i need a fucntion to delete them.
when running the app it terminates unexpectedly.
-I run VS as administrator
-folder and files are not protected and not in use
-i tryed to delete only one and woked correct
-i placed a counter to my loop and i noticed that it works correct till 5 pictures, if i increase the loop, app terminates unexpectedly with no error.
The problem may be caused by Access Violation Exception . Any suggestion how could i solve this?
when running the app it terminates unexpectedly.
-I run VS as administrator
-folder and files are not protected and not in use
-i tryed to delete only one and woked correct
-i placed a counter to my loop and i noticed that it works correct till 5 pictures, if i increase the loop, app terminates unexpectedly with no error.
C#:
System.IO.DirectoryInfo di = new DirectoryInfo("C:\\MS_ACCESS_SOFTWARE\\TestPic\\");
int Fcounter = 0;
try
{
foreach (FileInfo file in di.GetFiles())
{
if (Fcounter < 5)
{
file.Delete();
Fcounter++;
}
}
foreach (DirectoryInfo dir in di.GetDirectories())
{
dir.Delete(true);
}
}
catch (Exception ex)
{
MessageBox.Show("Error" + ex);
}
return "Finished";
Last edited: