/// <summary>
        /// Initializes a new instance of the <see cref="DeviceHub"/> class.
        /// </summary>
        public Focuser()
        {
            _driverID          = Marshal.GenerateProgIdForType(this.GetType());
            _driverDescription = GetDriverDescriptionFromAttribute();

            _logger = new TraceLogger("", "DeviceHubFocuser");
            ReadProfile();             // Read device configuration from the ASCOM Profile store

            _logger.LogMessage("Focuser", "Starting initialization");

            ConnectedState = false;             // Initialise connected to false
            Utilities      = new Util();        //Initialise util object

            // We need this to get the focuser ID.

            AppSettingsManager.LoadAppSettings();
            _logger.LogMessage("Focuser", "Completed initialization");
        }
        internal static void Startup(string[] args)
        {
            // Uncomment the following lines to allow the Visual Studio Debugger to be
            // attached to the server for debugging.

            //int procId = Process.GetCurrentProcess().Id;
            //string msg = String.Format( "Attach the debugger to process #{0} now.", procId );
            //MessageBox.Show( msg );

            Globals.UISyncContext = TaskScheduler.FromCurrentSynchronizationContext();

            LoadComObjectAssemblies();               // Load served COM class assemblies, get types

            if (!ProcessArguments(args))             // Register/Unregister
            {
                App.Current.Shutdown();

                return;
            }

            // Now that we are past the registration code, make sure that we are NOT
            // running As Administrator.

            if (IsElevated && IsUacEnabled)
            {
                MessageBox.Show("You cannot run this application with elevated access...Terminating!");
                App.Current.Shutdown();

                return;
            }

            // Initialize critical member variables.

            _objsInUse     = 0;
            _scopesInUse   = 0;
            _domesInUse    = 0;
            _focusersInUse = 0;
            _serverLocks   = 0;

            // Application Startup

            // Initialize our non-U/I services.

            ServiceInjector.InjectServices();

            // Create Device Hub App Settings and seed with default values.

            AppSettingsManager.CreateInitialAppSettings();

            // Load the saved position of the main window. Do this before the
            // window object is created so that the code-behind can pick up
            // the location.

            AppSettingsManager.LoadMainWindowSettings();

            // Create the View and ViewModel

            ViewModel  = new MainWindowViewModel();
            MainWindow = new MainWindow();

            // Create the U/I services.

            ServiceInjector.InjectUIServices(MainWindow);

            MainWindow.DataContext = ViewModel;
            MainWindow.Closing    += MainWindow_Closing;

            // Load the saved settings to ensure that everyone up-to-date. Be sure to do this
            // after the main window is created so we can set its location.

            AppSettingsManager.LoadAppSettings();

            LoadDeviceSettings();

            // Register the class factories of the served objects

            RegisterClassFactories();

            StartGarbageCollection(10000);                  // Collect garbage every 10 seconds.

            try
            {
                ShowMainWindow();
            }
            finally
            {
                AppSettingsManager.SaveAppSettings();

                // Update the dome settings to save the azimuth adjustment.

                SaveDomeSettings();

                // Revoke the class factories immediately.
                // Don't wait until the thread has stopped before
                // we perform revocation!!!

                RevokeClassFactories();

                MainWindow.DataContext = null;
                MainWindow             = null;
                ViewModel.Dispose();
                ViewModel = null;

                ServiceContainer.Instance.ClearAllServices();

                // Now stop the Garbage Collector task.

                StopGarbageCollection();
            }
        }