private static void Main(string[] args) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Settings.PersistentSettings.debugConsole) { AllocConsole(); // needs to be the first call in the program to prevent weird bugs } if (!Directory.Exists(Settings.StorageLocation)) { // Create Settings directory if it doesn't exist, as we need to stick our pidfile there. Directory.CreateDirectory(Settings.StorageLocation); } URIStartResult uriRes = URIStartResult.CLOSE; uriRes = IPCadapter.getInstance().HandleURIStart(args); switch (uriRes) { case URIStartResult.CLOSE: Environment.Exit(0); break; case URIStartResult.PARSE: Console.WriteLine($"Starting with args : {args[0]}"); break; case URIStartResult.CONTINUE: break; default: throw new ArgumentOutOfRangeException(); } socket = new ClientSocket(); //Create the Form Console interface. var thread = new Thread(OpenGUI); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { thread.SetApartmentState(ApartmentState.STA); } thread.Start(); while (Settings.conInterface is null) { Thread.Sleep(250); } Task.Factory.StartNew(() => socket.Init()) .Wait(); // run socket in background. Important to wait for init to have actually finished before continuing Task.Factory.StartNew(() => IPCadapter.getInstance().RegisterMinion()).Wait(); // Add a GLib Idle handler to fix the issue here. Idle.Add(delegate { Task.Factory.StartNew(() => GameMemReader.getInstance().RunLoop()); // run loop in background if (uriRes == URIStartResult.PARSE) { IPCadapter.getInstance().SendToken(args[0]); } return(false); }); thread.Join(); }