gpt4 book ai didi

c# - 检查 Windows 安装程序互斥锁的可用性

转载 作者:行者123 更新时间:2023-12-03 17:46:18 25 4
gpt4 key购买 nike

在我的一个集成测试中,我有两个线程卸载然后安装一个程序,但是当按顺序运行时,它们会生成错误 Failed to grab execution mutex. System error 258.
为了解决这个问题,我必须在卸载后 sleep 。我尝试检查 msiexec 进程是否正在运行,但始终为 2-3,因此这不是一个好的指标。有没有办法检查 msiexec 执行互斥锁是否可用?

最佳答案

    bool msiIsRunning = false;
try
{
using(var mutex = Mutex.OpenExisting(@"Global\_MSIExecute"))
{
msiIsRunning = true;
}
}
catch (Exception)
{
// Mutex not found; MSI isn't running
}

关于c# - 检查 Windows 安装程序互斥锁的可用性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10144268/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com