private static void Run(string settingsProfileName) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Application.ThreadException += Application_ThreadException; _initializer = new Initializer(settingsProfileName); _initializer.Start(); Application.Run(_initializer); }
static void Main(string[] args) { string appGuid = ((GuidAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(GuidAttribute), false).GetValue(0)).Value.ToString(); string mutexId = string.Format("Global\\{{{0}}}", appGuid); using (var mutex = new Mutex(false, mutexId)) { var allowEveryoneRule = new MutexAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), MutexRights.FullControl, AccessControlType.Allow); var securitySettings = new MutexSecurity(); securitySettings.AddAccessRule(allowEveryoneRule); mutex.SetAccessControl(securitySettings); // edited by acidzombie24 var hasHandle = false; try { try { hasHandle = mutex.WaitOne(2000, false); if (hasHandle == false) { MessageBox.Show("osu!StreamCompanion is already running.", "Error"); return; } } catch (AbandonedMutexException) { hasHandle = true; } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Application.ThreadException += Application_ThreadException; _initializer = new Initializer(); _initializer.Start(); Application.Run(_initializer); } finally { if (hasHandle) { mutex.ReleaseMutex(); } } } }
static void Main(string[] args) { if (OS.IsWindows) { Console.OutputEncoding = System.Text.Encoding.UTF8; } // expect first argument to be config file name if (args.Length > 0) { Config.MergeCommandLineArgumentsWithConfiguration(LeanArgumentParser.ParseArguments(args)); } var liveMode = Config.GetBool("live-mode"); //Name thread for the profiler: Thread.CurrentThread.Name = "Algorithm Analysis Thread"; Initializer.Start(); leanEngineSystemHandlers = Initializer.GetSystemHandlers(); //-> Pull job from QuantConnect job queue, or, pull local build: string assemblyPath; job = leanEngineSystemHandlers.JobQueue.NextJob(out assemblyPath); leanEngineAlgorithmHandlers = Initializer.GetAlgorithmHandlers(); if (job == null) { const string jobNullMessage = "Engine.Main(): Sorry we could not process this algorithm request."; Log.Error(jobNullMessage); throw new ArgumentException(jobNullMessage); } // if the job version doesn't match this instance version then we can't process it // we also don't want to reprocess redelivered jobs if (job.Redelivered) { Log.Error("Engine.Run(): Job Version: " + job.Version + " Deployed Version: " + Globals.Version + " Redelivered: " + job.Redelivered); //Tiny chance there was an uncontrolled collapse of a server, resulting in an old user task circulating. //In this event kill the old algorithm and leave a message so the user can later review. leanEngineSystemHandlers.Api.SetAlgorithmStatus(job.AlgorithmId, AlgorithmStatus.RuntimeError, _collapseMessage); leanEngineSystemHandlers.Notify.SetAuthentication(job); leanEngineSystemHandlers.Notify.Send(new RuntimeErrorPacket(job.UserId, job.AlgorithmId, _collapseMessage)); leanEngineSystemHandlers.JobQueue.AcknowledgeJob(job); Exit(1); } try { // Set our exit handler for the algorithm Console.CancelKeyPress += new ConsoleCancelEventHandler(ExitKeyPress); // Create the algorithm manager and start our engine algorithmManager = new AlgorithmManager(liveMode, job); leanEngineSystemHandlers.LeanManager.Initialize(leanEngineSystemHandlers, leanEngineAlgorithmHandlers, job, algorithmManager); var engine = new Engine.Engine(leanEngineSystemHandlers, leanEngineAlgorithmHandlers, liveMode); engine.Run(job, algorithmManager, assemblyPath, WorkerThread.Instance); } finally { var algorithmStatus = algorithmManager?.State ?? AlgorithmStatus.DeployError; Exit(algorithmStatus != AlgorithmStatus.Completed ? 1 : 0); } }