mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-02 11:34:08 +02:00
Kill subprocess if it doesn't exit after the app is closed
This commit is contained in:
parent
2be46464d6
commit
710a7524a1
@ -1,4 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using CefSharp.BrowserSubprocess;
|
using CefSharp.BrowserSubprocess;
|
||||||
|
|
||||||
namespace TweetDuck.Browser{
|
namespace TweetDuck.Browser{
|
||||||
@ -8,10 +10,20 @@ static class Program{
|
|||||||
private static int Main(string[] args){
|
private static int Main(string[] args){
|
||||||
SubProcess.EnableHighDPISupport();
|
SubProcess.EnableHighDPISupport();
|
||||||
|
|
||||||
const string typePrefix = "--type=";
|
string FindArg(string key){
|
||||||
string type = Array.Find(args, arg => arg.StartsWith(typePrefix, StringComparison.OrdinalIgnoreCase)).Substring(typePrefix.Length);
|
return Array.Find(args, arg => arg.StartsWith(key, StringComparison.OrdinalIgnoreCase)).Substring(key.Length);
|
||||||
|
}
|
||||||
|
|
||||||
if (type == "renderer"){
|
const string typePrefix = "--type=";
|
||||||
|
const string parentIdPrefix = "--host-process-id=";
|
||||||
|
|
||||||
|
if (!int.TryParse(FindArg(parentIdPrefix), out int parentId)){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Task.Factory.StartNew(() => KillWhenHung(parentId), TaskCreationOptions.LongRunning);
|
||||||
|
|
||||||
|
if (FindArg(typePrefix) == "renderer"){
|
||||||
using(SubProcess subProcess = new SubProcess(args)){
|
using(SubProcess subProcess = new SubProcess(args)){
|
||||||
return subProcess.Run();
|
return subProcess.Run();
|
||||||
}
|
}
|
||||||
@ -20,5 +32,18 @@ private static int Main(string[] args){
|
|||||||
return SubProcess.ExecuteProcess();
|
return SubProcess.ExecuteProcess();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static async void KillWhenHung(int parentId){
|
||||||
|
try{
|
||||||
|
using(Process process = Process.GetProcessById(parentId)){
|
||||||
|
process.WaitForExit();
|
||||||
|
}
|
||||||
|
}catch{
|
||||||
|
// ded
|
||||||
|
}
|
||||||
|
|
||||||
|
await Task.Delay(10000);
|
||||||
|
Environment.Exit(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user