using System;
using CefSharp.BrowserSubprocess;

namespace TweetDuck.Browser{
    static class Program{
        internal const string Version = "1.4.1.0";

        private static int Main(string[] args){
            SubProcess.EnableHighDPISupport();
            
            const string typePrefix = "--type=";
            string type = Array.Find(args, arg => arg.StartsWith(typePrefix, StringComparison.OrdinalIgnoreCase)).Substring(typePrefix.Length);

            if (type == "renderer"){
                using(SubProcess subProcess = new SubProcess(args)){
                    return subProcess.Run();
                }
            }
            else{
                return SubProcess.ExecuteProcess();
            }
        }
    }
}

using System;
using System.Diagnostics;
using System.Threading.Tasks;
using CefSharp.BrowserSubprocess;

namespace TweetDuck.Browser{
    static class Program{
        internal const string Version = "1.4.1.0";

        private static int Main(string[] args){
            SubProcess.EnableHighDPISupport();
            
            string FindArg(string key){
                return Array.Find(args, arg => arg.StartsWith(key, StringComparison.OrdinalIgnoreCase)).Substring(key.Length);
            }

            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)){
                    return subProcess.Run();
                }
            }
            else{
                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);
        }
    }
}

Kill subprocess if it doesn't exit after the app is closed
Kill subprocess if it doesn't exit after the app is closed
