我創建一個BackgroundWorker的和它的DoWork函數內終止一個控制檯模式應用程序,我有以下代碼:如何從一個BackgroundWorker
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);
}
}
按照這個代碼,我應該只看到一個郵件,因爲應用程序存在,但是我看到8封郵件(對於每個迭代的文件)。爲什麼應用程序不退出?我想立即殺死應用程序。
這是一個控制檯應用程序。
也許這段代碼是在一個單獨的線程中執行的,並且發生異常。 – lstern
是的BackgroundWorker正在執行的代碼中的代碼如上所示。 –