拼多多拍单关联闪退修复

This commit is contained in:
wule committed 2026-10-16 12:04:12 +08:00
1 parent b2d6d81e07
commit ebccdbc28c
4 files changed
+140 -81

No files matched your search

@@ -190,6 +190,41 @@ namespace _29WxOrderWpf.ViewModels
CefWebBrowser = null;
}
public int GetRenderProcessId()
{
int parentPid = Process.GetCurrentProcess().Id;
// 查找所有名为 CefSharp.BrowserSubprocess 且父进程为当前应用的进程
var subprocesses = Process.GetProcessesByName("CefSharp.BrowserSubprocess")
.Where(p =>
{
try
{
return p.SessionId == Process.GetCurrentProcess().SessionId && GetParentProcessId(p.Id) == parentPid;
}
catch { return false; }
});
// 返回第一个匹配的 Render 进程 ID,实际可能有多个
return subprocesses.FirstOrDefault()?.Id ?? -1;
}
// 辅助方法:获取父进程 ID (需引用 System.Management 或使用 P/Invoke)
private static int GetParentProcessId(int processId)
{
using (var query = new System.Management.ManagementObjectSearcher(
$"SELECT ParentProcessId FROM Win32_Process WHERE ProcessId = {processId}"))
{
using (var results = query.Get())
{
foreach (System.Management.ManagementObject obj in results)
{
return Convert.ToInt32(obj["ParentProcessId"]);
}
}
}
return -1;
}
public static void CleanupBrowserSubprocesses(List<Process> processes = null)
{
// 有可能释放错误导致程序崩溃,废弃