我想在应用程序运行时停止卸载它。我想通过视觉工作室设置和部署来做到这一点。我在安装程序类中添加了以下代码,然后在操作列表中调用,但它不起作用。
public static bool ApplicationIsBusy()
{
Process application = null;
foreach (var process in Process.GetProcesses())
{
if (!process.ProcessName.Contains("applicationname")) continue;
application = process;
break;
}
if (application != null && application.Responding)
{
return true;
}
else
{
return false;
}
}
public override void Uninstall(IDictionary savedState)
{
base. Uninstall(savedState);
if (ApplicationIsBusy()==true)
throw new ApplicationException("Prevent uninstall while application busy.");
}
protected override void OnBeforeUninstall(IDictionary savedState)
{
base.OnBeforeUninstall(savedState);
if (ApplicationIsBusy()==true)
throw new ApplicationException("Prevent uninstall while application busy.");
}