private void StartInternal() { Utility.SetCurrentThreadAffinity(); // Set the verbose flag if (_cmdLn.verbose) { _verbose = true; } // 1) Create all the EmulatorComponents first and configure them properly based on the config file if (_cmdLn.useDefaultConfig) { LoadDefaultComponents(); } for (int iConfig = 0; iConfig < _cmdLn.configFiles.Count; iConfig++) { string configFileName = _cmdLn.configFiles[iConfig]; ApplyConfig(configFileName); } string defaultConfigFileName = Application.ExecutablePath + ".emulatorconfig"; if (File.Exists(defaultConfigFileName)) { ApplyConfig(defaultConfigFileName); } // 2) Calling Setup() on all EmulatorComponents to allow each component to check for the // validity of each properties, allocate memory, ... etc. SetupComponent(); CheckForRequiredComponents(); // 3) Now that the components are in the correct state. Register each component with its collection, // if there is one. RegisterComponentsWithCollection(); try { //Initialization of EmulatorNative required before EmulatorComponents //TimingServices, for example, is dependent on EmulatorNative initialization _emulatorNative.Initialize(this.ManagedHal); // 4) Call InitializeComponent() on all EmulatorComponents to put each component into a // working / running state. InitializeComponent(); // 5) Load the assemblies LoadAssemblies(); // 6) Get into the initial state if (_cmdLn.waitForDebuggerOnStartup) { _emulatorNative.WaitForDebuggerOnStartup(); } if (String.IsNullOrEmpty(_cmdLn.commandLineArguments) == false) { _emulatorNative.SetCommandLineArguments(_cmdLn.commandLineArguments); } _emulatorState = EmulatorState.Running; //start time -- this allows components to hook into events before execution starts TimingServices.ResumeTime(); // 7) We start the emulator. this.Run(); } catch (EmulatorException e) { // if we are shutting down and received the unexpected shut down exception, we'll handle the exception if (e.ErrorCode == CLR_ERRORCODE.CLR_E_SHUTTING_DOWN) { Debug.Assert(this.State >= EmulatorState.ShutDown); } else { // otherwise, re-throw. throw; } } finally { bool needUnintialization = (this.State >= EmulatorState.Initialize); Stop(); if (needUnintialization) { UninitializeComponent(); } } }