我面臨一個問題,即我的客戶已經在運行應用程序appA。然後他們轉到桌面(不殺死appA),然後使用PowerShell通過運行appA.ps1升級應用程序。之後,安裝後點擊appA - >get an exception
。我猜根本原因是有另一個實例正在運行。如何檢查並殺死我的應用程序的另一個實例?
我的問題是如何檢查我的應用程序是否已在運行?我可以殺死它嗎?
另外,我的應用程序是Windows 8商店,C#。
我面臨一個問題,即我的客戶已經在運行應用程序appA。然後他們轉到桌面(不殺死appA),然後使用PowerShell通過運行appA.ps1升級應用程序。之後,安裝後點擊appA - >get an exception
。我猜根本原因是有另一個實例正在運行。如何檢查並殺死我的應用程序的另一個實例?
我的問題是如何檢查我的應用程序是否已在運行?我可以殺死它嗎?
另外,我的應用程序是Windows 8商店,C#。
所有Metro風格應用程序的高度沙盒環境中工作,有沒有辦法直接啓動的外部應用程序。
您無法訪問Windows應用程序進程。不幸的是,你無法檢查運行的Windows應用程序。
到目前爲止我還沒有找到其他方法。
沒有Metro風格的應用程序
首先,你需要的進程:
var processes = Process.GetProcessesByName("your application name")
要檢查程序是否已經運行:
var isRunning = processes.Length > 1;
然後你通過它們循環並關閉進程:
foreach (var process in processes)
{
process.CloseMainWindow();
// OR more aggressive:
process.Kill();
}
,如果你的魔杖,讓您的當前實例運行,並殺死你的應用程序的所有其他情況下,你可以做到這一點
// get current process
Process current = Process.GetCurrentProcess();
// get all the processes with currnent process name
Process[] processes = Process.GetProcessesByName(current.ProcessName);
foreach (Process process in processes)
{
//Ignore the current process
if (process.Id != current.Id)
{
process.Kill();
}
}
使用命名空間System.Diagnostics程序;
你確定這個異常是由裝載的升級引起的嗎?發生了什麼異常? – WiredPrairie