示例#1
0
        private void InitializeApplication(
            InProcessSettings settings,
            AppDomain createdDomain)
        {
            inProcess         = true;
            inProcessSettings = settings;
            appDomain         = createdDomain;

            mainApplicationThread = new Thread(InitializeApplicationWorker);
            mainApplicationThread.SetApartmentState(ApartmentState.STA);

            mainApplicationThread.Start(this);
        }
示例#2
0
        /// <summary>
        /// Starts a new application using the settings provided and returns an
        /// AutomatedApplication to wrap it.
        /// </summary>
        /// <param name="settings">
        /// The settings specify that the application should be started inside
        /// the current process.  They specify the application to create,
        /// which is described by the application path and type name. If
        /// applicable the settings also describe the delegates to set.
        /// </param>
        /// <returns>
        /// Returns an AutomatedApplication handle which gives the user access
        /// to the main window and the ability to close the application.
        /// </returns>
        public static AutomatedApplication Start(InProcessSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            if (settings.Path == null)
            {
                throw new ArgumentException("settings.Path should not be null");
            }

            if (settings.ApplicationType == null)
            {
                throw new ArgumentException(
                          "settings.ApplicationType should not be null");
            }

            AutomatedApplication automatedApplication;

            if (Assembly.GetEntryAssembly() != null)
            {
                AppDomain appDomain = AppDomain.CreateDomain("Automated Application Domain");

                automatedApplication = (AutomatedApplication)appDomain.CreateInstanceAndUnwrap(
                    Assembly.GetExecutingAssembly().GetName().Name,
                    typeof(AutomatedApplication).FullName);

                automatedApplication.InitializeApplication(settings, appDomain);
            }
            else
            {
                automatedApplication = new AutomatedApplication();
                automatedApplication.InitializeApplication(settings, null);
            }

            return(automatedApplication);
        }