I am creating one BackgroundWorker and inside its DoWork function I have the following code:
foreach (string newFilepath in newFilesPath)
{
if (!File.Exists(encryptedFilePath))
{
encryptedFiles.Add(encryptedFilePath);
Helper.SendErrorMail(null, "Could not find encrypted file.", encryptedFilePath);
Application.Exit();
}
else
{
Helper.Count_DataFeeds++;
File.Delete(newFilepath);
}
}
As per this code I should see only one mail because the Application exists, however I am seeing 8 mails(for each file it is iterating). Why application is not quitting ? I want to kill the application at once.
It is a console application.
Environment.Exit is what was needed.