static void Main(string[] args) { Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); if (!LoadComObjectAssemblies()) { return; // Load served COM class assemblies, get types } if (!ProcessArguments(args)) { return; // Register/Unregister } // Initialize critical member variables. objsInUse = 0; serverLocks = 0; MainThreadId = GetCurrentThreadId(); Thread.CurrentThread.Name = "Main Thread"; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); s_MainForm = new frmMain(); if (StartedByCOM) { s_MainForm.WindowState = FormWindowState.Normal; } // Register the class factories of the served objects RegisterClassFactories(); // Start up the garbage collection thread. GarbageCollection GarbageCollector = new GarbageCollection(1000); Thread GCThread = new Thread(new ThreadStart(GarbageCollector.GCWatch)); GCThread.Name = "Garbage Collection Thread"; GCThread.Start(); // // Start the message loop. This serializes incoming calls to our // served COM objects, making this act like the VB6 equivalent! // try { Application.Run(s_MainForm); } finally { // Revoke the class factories immediately. // Don't wait until the thread has stopped before // we perform revocation!!! RevokeClassFactories(); // Now stop the Garbage Collector thread. GarbageCollector.StopThread(); GarbageCollector.WaitForThreadToStop(); } }
static void Main(string[] args) { if (!LoadComObjectAssemblies()) { return; // Load served COM class assemblies, get types } if (!ProcessArguments(args)) { return; // Register/Unregister } // Initialize critical member variables. m_iObjsInUse = 0; m_iServerLocks = 0; m_uiMainThreadId = GetCurrentThreadId(); Thread.CurrentThread.Name = "Main Thread"; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); m_MainForm = new frmMain(); //if (m_bComStart) m_MainForm.WindowState = FormWindowState.Minimized; m_MainForm.Visible = true; // Initialize hardware layer RotatorHardware.Initialize(); // Start up the garbage collection thread. GarbageCollection GarbageCollector = new GarbageCollection(1000); Thread GCThread = new Thread(new ThreadStart(GarbageCollector.GCWatch)); GCThread.Name = "Garbage Collection Thread"; GCThread.Start(); // Register the class factories of the served objects RegisterClassFactories(); // // Start the message loop. This serializes incoming calls to our // served COM objects, making this act like the VB6 equivalent! // Application.Run(m_MainForm); // Exiting... Revoke the class factories immediately. // Don't wait until the thread has stopped before // we perform revocation!!! RevokeClassFactories(); // Now stop the Garbage Collector thread. GarbageCollector.StopThread(); GarbageCollector.WaitForThreadToStop(); // And finally save the hardware state for next time RotatorHardware.Finalize_(); }
private static void Main(string[] args) { if (!LoadComObjectAssemblies()) { return; // Load served COM class assemblies, get types } if (!ProcessArguments(args)) { return; // Register/Unregister } // Initialize critical member variables. objsInUse = 0; serverLocks = 0; MainThreadId = GetCurrentThreadId(); Thread.CurrentThread.Name = "Main Thread"; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Register the class factories of the served objects RegisterClassFactories(); // Start up the garbage collection thread. GarbageCollection GarbageCollector = new GarbageCollection(1000); Thread GCThread = new Thread(new ThreadStart(GarbageCollector.GCWatch)); GCThread.Name = "Garbage Collection Thread"; GCThread.Start(); // // Start the message loop. This serializes incoming calls to our // served COM objects, making this act like the VB6 equivalent! // try { //We don't actually need to start a form. This will run under the Background Processes section of Task Manager instead of Apps Application.Run(); } finally { // Revoke the class factories immediately. // Don't wait until the thread has stopped before // we perform revocation!!! RevokeClassFactories(); // Now stop the Garbage Collector thread. GarbageCollector.StopThread(); GarbageCollector.WaitForThreadToStop(); } }
static void Main(string[] args) { //MessageBox.Show("Test"); // used to allow debugging if (!LoadComObjectAssemblies()) { return; // Load served COM class assemblies, get types } if (!ProcessArguments(args)) { return; // Register/Unregister } // Initialize critical member variables. m_iObjsInUse = 0; m_iServerLocks = 0; m_uiMainThreadId = GetCurrentThreadId(); Thread.CurrentThread.Name = "Main Thread"; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Register the class factories of the served objects RegisterClassFactories(); // Start up the garbage collection thread. GarbageCollection GarbageCollector = new GarbageCollection(1000); Thread GCThread = new Thread(new ThreadStart(GarbageCollector.GCWatch)); GCThread.Name = "Garbage Collection Thread"; GCThread.Start(); try { // // Start the message loop. This serializes incoming calls to our // served COM objects, making this act like the VB6 equivalent! // string startupUrls = "--urls=http://127.0.0.1:4321"; using (Profile profile = new Profile()) { try { startupUrls = profile.GetValue(SharedResources.PROGRAM_ID, "AlpacaStartupUrls", string.Empty, "--urls=http://127.0.0.1:4321"); } catch { } } global::TelescopeSimulator.Alpaca.Program.Start(new string[] { startupUrls }); } catch (Exception ex) { var str = string.Format("Fatal error in the Simulator server: {0}", ex); MessageBox.Show(str); throw; } finally { // Save the last used Azimuth and Altitude TelescopeHardware.TL.LogMessage("Main", string.Format("Saving shutdown values for Azimuth: {0}, Altitude: {1}", TelescopeHardware.Azimuth, TelescopeHardware.Altitude)); using (Profile profile = new Profile()) { // Best endeavours to save the shutdown alt/az for use on next startup if required try { profile.WriteValue(SharedResources.PROGRAM_ID, "ShutdownAzimuth", TelescopeHardware.Azimuth.ToString(CultureInfo.InvariantCulture)); } catch { } try { profile.WriteValue(SharedResources.PROGRAM_ID, "ShutdownAltitude", TelescopeHardware.Altitude.ToString(CultureInfo.InvariantCulture)); } catch { } } // Revoke the class factories immediately. // Don't wait until the thread has stopped before // we perform revocation!!! RevokeClassFactories(); // Now stop the Garbage Collector thread. GarbageCollector.StopThread(); GarbageCollector.WaitForThreadToStop(); } }