I have a Listbox which work with specific extension files. If i choose another format, my application automatically converts the files to the correct format in the same folder (another extension) and add all the files with the wrong extension to a List (listToRemove) and remove them from my Listbox after i clean my List but first i want to delete all this files from my computer and my problem is that my appliction deleted also the file with the correct extension
for (int i = 0; i < listBoxFiles.Items.Count; i++)
{
string path = (string)listBoxFiles.Items[i];
FileInfo fileInfo = new FileInfo(path);
if (fileInfo.Extension != ".avi")
{
listToRemove.Add(path);
}
}
if (listToRemove.Count != 0)
{
//method who convert the files to the new format and add the new files into my Listbox
(new System.Threading.Thread(sendFilesToConvertToAvi)).Start();
}
foreach (string file in listToRemove)
{
File.Delete(file);
listBoxFiles.Items.Remove(file);
}
public void sendFilesToConvertToAvi()
{
if (listToRemove.Count == 0)
{
return;
}
foreach (String file in listToRemove)
{
FileInfo fileInfo = new FileInfo(file);
myClassWhoConvertTheFiles = new myClassWhoConvertTheFiles (fileInfo);
this.Invoke((MethodInvoker)delegate
{
listBoxFiles.Items.Add(myClassWhoConvertTheFiles ._newFileName);
});
count++;
}
listToRemove.RemoveRange(0, listToRemove.Count);
}
The problem is most likely in:
The code for which you don’t show. This:
looks like it should be in a callback from sendFilesToConvertToAvi. i.e. post convert.