目前我正在处理我的应用程序自动更新function。 所以当我试图删除文件夹,抛出其他进程使用的exception。 所以我打算检查另一个进程使用的文件夹,我将跳过自动更新function。 另一个进程正在使用如何检查文件夹。 我在使用下面的代码时遇到exception:
private static ArrayList getFileProcesses(string strFile) { myProcessArray.Clear(); Process[] processes = Process.GetProcesses(); int i = 0; for (i = 0; i <= processes.GetUpperBound(0) - 1; i++) { myProcess = processes[i]; //if (!myProcess.HasExited) //This will cause an "Access is denied" error if (myProcess.Threads.Count > 0) { try { ProcessModuleCollection modules = myProcess.Modules; int j = 0; for (j = 0; j <= modules.Count - 1; j++) { if ((modules[j].FileName.ToLower().CompareTo(strFile.ToLower()) == 0)) { myProcessArray.Add(myProcess); break; // TODO: might not be correct. Was : Exit For } } } catch (Exception exception) { //MsgBox(("Error : " & exception.Message)) } } } return myProcessArray; }