ExecuteAssembly() private méthode

private ExecuteAssembly ( Assembly assembly, string args ) : int
assembly Assembly
args string
Résultat int
        public void LaunchAppDomain()
        {
            UnloadAppDomain();
            QAppDomain = AppDomain.CreateDomain("QAppDomain");
            AppDomain.MonitoringIsEnabled = true;

            string path = Win32Hooks.HookManager.Instance.AssemblyPath;

            if(this.EveAccount.DX11) {

                t = new Thread(delegate() { QAppDomain.ExecuteAssembly(path + "\\Questor\\Questor.exe",args: new String[] {"-i","-c", Win32Hooks.HookManager.Instance.CharName,"-u", Win32Hooks.HookManager.Instance.EveAccount.AccountName, "-p", Win32Hooks.HookManager.Instance.EveAccount.Password}); });
            } else {

                t = new Thread(delegate() { QAppDomain.ExecuteAssembly(path + "\\Questor\\Questor.exe",args: new String[] {"-d","-i","-c", Win32Hooks.HookManager.Instance.CharName,"-u", Win32Hooks.HookManager.Instance.EveAccount.AccountName, "-p", Win32Hooks.HookManager.Instance.EveAccount.Password}); });
            }
            t.Start();
        }
Exemple #2
0
        public static void StartADemo(AppWidgetFactory appWidgetFactory)
        {
            if (usedMainThread)
            {
                System.AppDomainSetup domainSetup = new AppDomainSetup();
                domainSetup.ApplicationBase = ".";
                System.AppDomain newDomain = null;

                bool usePermissionTest = false;
                if (usePermissionTest)
                {
                    System.Security.PermissionSet permissionSet = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None);
                    permissionSet.AddPermission(new System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityPermissionFlag.Execution));
                    permissionSet.AddPermission(new System.Security.Permissions.FileIOPermission(System.Security.Permissions.PermissionState.Unrestricted));

                    newDomain = System.AppDomain.CreateDomain(appWidgetFactory.GetAppParameters().title, null, domainSetup, permissionSet, null);
                }
                else
                {
                    newDomain = System.AppDomain.CreateDomain(appWidgetFactory.GetAppParameters().title);
                }

                string[] args = { appWidgetFactory.GetAppParameters().title };
                newDomain.ExecuteAssembly("./DemoRunner.exe", args);
                //System.AppDomain.Unload(newDomain);
            }
            else
            {
                usedMainThread = true;
                appWidgetFactory.CreateWidgetAndRunInWindow();
                //appWidgetFactory.CreateWidgetAndRunInWindow(AppWidgetFactory.ValidDepthVaules.Depth32, AppWidgetFactory.RenderSurface.OpenGL);
            }
        }
Exemple #3
0
        private void ReStart()
        {
            Process thisprocess = Process.GetCurrentProcess();
            string  me          = thisprocess.MainModule.FileName;

            string sApplicationDirectory = AppDomain.CurrentDomain.BaseDirectory;
            string sAppName = "RadarBidClient";

            System.AppDomainSetup oSetup = new System.AppDomainSetup();
            string sApplicationFile      = null;

            // Use this to ensure that if the application is running when the user performs the update, that we don't run into file locking issues.
            oSetup.ShadowCopyFiles = "true";
            oSetup.ApplicationName = sAppName;

            // Generate the name of the DLL we are going to launch
            sApplicationFile = Path.Combine(sApplicationDirectory, sAppName + ".exe");

            oSetup.ApplicationBase    = sApplicationDirectory;
            oSetup.ConfigurationFile  = sApplicationFile + ".config";
            oSetup.LoaderOptimization = LoaderOptimization.MultiDomain;

            // Launch the application
            System.AppDomain oAppDomain = AppDomain.CreateDomain(sAppName, AppDomain.CurrentDomain.Evidence, oSetup);
            oAppDomain.SetData("App", sAppName);
            // oAppDomain.SetData("User", sUserName);
            // oAppDomain.SetData("Pwd", sUserPassword);

            oAppDomain.ExecuteAssembly(sApplicationFile);

            // When the launched application closes, close this application as well
            // Application.Exit();
            Application.Current.Shutdown();
        }
        private void application2Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            //Strange things happens when exiting the Console Application. When pressing the "x" in the window, it closes even the forms application
            //and closing then re-opening the console application creates an IOexception. It seems something is not being closed properly. A solution could be
            //to re-create the appdomain everytime the console app starts. This is an ugly temporary solution, but it works for now.

            cDomain = AppDomain.CreateDomain("ConsoleDomain");
            //domain.CreateInstanceFromAndUnwrap(@"C:\Users\Mads\Documents\GitHub\ProgrammeringIII\Programmering III\ApplicationDomainsConsole\bin\Debug\ApplicationDomainsConsole.exe", ")
            cDomain.ExecuteAssembly(@"C:\Users\Mads\Documents\GitHub\ProgrammeringIII\Programmering III\ApplicationDomainsConsole\bin\Debug\ApplicationDomainsConsole.exe");
        }
Exemple #5
0
        //private static void domain_DomainUnload(object sender, EventArgs e)
        //{
        //    Trace.WriteLine("domain_DomainUnload()");
        //}

        static void Run(object runSourceRestartParameters)
        {
            __domain = AppDomain.CreateDomain(__runsourceDomainName);
            if (runSourceRestartParameters != null)
            {
                __domain.SetData(__domainRestartParametersName, runSourceRestartParameters);
                runSourceRestartParameters = null;
            }
            __domain.ExecuteAssembly(Path.Combine(zapp.GetAppDirectory(), __runsourceExeName));
        }
Exemple #6
0
        static void RunExeInAppDomain(string assemblyFilename)
        {
            // Create an Application Domain:
            System.AppDomain newDomain = System.AppDomain.CreateDomain("NewApplicationDomain");

            // Load and execute an assembly:
            newDomain.ExecuteAssembly(assemblyFilename, new[] { "test" });

            // Unload the application domain:
            System.AppDomain.Unload(newDomain);
        }
    public static void Main()
    {
        // Create an Application Domain:
        System.AppDomain newDomain = System.AppDomain.CreateDomain("NewApplicationDomain");

        // Load and execute an assembly:
        newDomain.ExecuteAssembly(@"generic-unloading-sub.2.exe");

        DoGenericStuff();

        // Unload the application domain:
        System.AppDomain.Unload(newDomain);

        DoOtherGenericStuff();
    }
        private static void SwitchDomainForRazorEngine()
        {
            if (AppDomain.CurrentDomain.IsDefaultAppDomain())
            {
                // RazorEngine cannot clean up from the default appdomain...
                //Console.WriteLine("Switching to secound AppDomain, for RazorEngine...");
                AppDomainSetup adSetup = new AppDomainSetup();
                adSetup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
                var current = AppDomain.CurrentDomain;
                // You only need to add strongnames when your appdomain is not a full trust environment.
                var strongNames = new StrongName[0];

                _domain = AppDomain.CreateDomain(
                    "MyMainDomain", null,
                    current.SetupInformation, new PermissionSet(PermissionState.Unrestricted),
                    strongNames);
                _domain.ExecuteAssembly(Assembly.GetExecutingAssembly().Location);
            }
        }
Exemple #9
0
        public override void Start()
        {
            var setup = AppDomainSetup();

            try
            {
                domain = AppDomain.CreateDomain(executable, new Evidence(), setup);
                thread = new Thread(() => domain.ExecuteAssembly(GetExecutablePath()));
                thread.Start();

            }
            catch (Exception)
            {
                AppDomain.Unload(domain);
                domain = null;
                thread = null;
                throw;
            }
        }
        public override void loadServer(string filename)
        {
            if (appDomain != null)
                throw new ApplicationException("Server is already loaded");

            appDomain = AppDomain.CreateDomain(Utils.randomName(15, 20));
            thread = new Thread(new ThreadStart(() => {
                try {
                    appDomain.ExecuteAssembly(filename, null, new string[] { ipcName, ipcUri });
                }
                catch (NullReferenceException) {
                    // Here if appDomain was set to null by Dispose() before this thread started
                }
                catch (AppDomainUnloadedException) {
                    // Here if it was unloaded by Dispose()
                }
                unloadAppDomain(appDomain);
                appDomain = null;
            }));
            thread.Start();
        }
Exemple #11
0
        static void Main(string[] args)
        {
            //这里获取当前程序域
            System.AppDomain currentDomain = System.AppDomain.CurrentDomain;
            Console.WriteLine(currentDomain.FriendlyName);

            //这里创建一个程序域 并在这个程序域中 运行AppDomain.exe
            System.AppDomain secondDomain = System.AppDomain.CreateDomain("New AppDomain");
            secondDomain.ExecuteAssembly("AppDomain.exe");

            //这里创建一个其它程序域的对象
            var cls = secondDomain.CreateInstanceFrom("Cs8.exe", "AppDomain.Demo", false, System.Reflection.BindingFlags.Default, null, new object[2] {
                1, 2
            }, null, null);
            //这里使用动态类型 是因为没有引用Cs8.exe程序集 所以取不到AppDomain.Demo类型(实际使用中是可以引用Cs8.exe程序集的)
            dynamic clsi = cls.Unwrap();

            Console.WriteLine(clsi.GetType().ToString());
            Console.WriteLine("{0} {1}", clsi.Var1, clsi.Var2);

            //这里清除掉程序域
            System.AppDomain.Unload(secondDomain);
        }
 private static int ExecuteAssembly(string exePath, AppDomain domain)
 {
     return domain.ExecuteAssembly(exePath);
 }
Exemple #13
0
 private static void RunAssembly(AppDomain appDomain)
 {
     appDomain.ExecuteAssembly("../../../WPFGuestApp/bin/Debug/WPFGuestApp.exe");
 }
 private static void RunAssembly(AppDomain appDomain)
 {
     appDomain.ExecuteAssembly("../../../LoadedAppDomain/bin/Debug/LoadedAppDomain.exe");
 }
		internal void StartFieldWorksThread()
		{
			m_FieldWorksDomain = AppDomain.CreateDomain("Running FieldWorks Domain");
			GetFieldWorksInfo().PretendNotRunningUnitTests();
			// FIXME: use FwAppArgs.kProject and FwAppArgs.kApp
			m_FieldWorksDomain.ExecuteAssembly(typeof(FieldWorks).Assembly.Location, null, new string[] {"-app", App, "-db", Db});
		}
 private void InvokeAppDomain(AppDomain domain)
 {
     domain.ExecuteAssembly(domain.FriendlyName);
 }
        private void Run()
        {
            string assemblyFile = Assembly.GetEntryAssembly().Location;
            string assemblyFolder = Path.GetDirectoryName(assemblyFile);
            string assemblyFileName = Path.GetFileNameWithoutExtension(assemblyFile);

            var versionDirectory = new VersionDirectoryFinder(log).GetVersionDirectory(assemblyFolder);

            if (versionDirectory == null)
            {
                log.Error("Cannot find any valid directory, which has a name with version pattern.");
                Console.ReadKey();
                return;
            }

            var exeDirectory = new DirectoryInfo(Path.Combine(versionDirectory.FullName, assemblyFileName));
            var files = exeDirectory.GetFiles("*.exe");
            if (files.Length == 0)
                throw new FileNotFoundException(string.Format("Cannot find a file with 'exe' extension inside '{0}'",
                                                              exeDirectory.FullName));
            if (files.Length > 1)
                throw new InvalidOperationException(string.Format("There is more than 1 file with 'exe' extension inside '{0}'",
                                                                  exeDirectory.FullName));

            var targetFile = files[0].FullName;
            var targetFolder = Path.GetDirectoryName(targetFile);

            var targetFileConfig = GetConfigurationFilename(targetFile);

            var currentFileConfig = GetConfigurationFilename(assemblyFile);

            //targetFileConfig = new ConfigurationFileMerger().MergeFiles(targetFileConfig, currentFileConfig);

            try
            {
                domain = AppDomain.CreateDomain(AppDomain.CurrentDomain.FriendlyName + "_bootstrapped",
                                                    AppDomain.CurrentDomain.Evidence,
                                                    new AppDomainSetup
                                                        {
                                                            ConfigurationFile = targetFileConfig,
                                                            ApplicationBase = targetFolder,
                                                        });

                var logger = (UnhandledExceptionLogger)domain.CreateInstanceFromAndUnwrap(Assembly.GetExecutingAssembly().Location,
                                                   typeof(UnhandledExceptionLogger).FullName,
                                                   false, BindingFlags.Default, null, null,
                                                   Thread.CurrentThread.CurrentCulture, null);
                logger.ProcessUnhandledExceptions();

                BootstrapperParameters.WriteToDomain(new BootstrapperParameters
                    {
                        BootstrapperFile = assemblyFile,
                        ConfigurationFile = currentFileConfig,
                    }, domain);

            //				var newArgs = new List<string>(args);
            //				newArgs.AddRange(.ToArray());
                var returnValue = domain.ExecuteAssembly(targetFile, args);
                AppDomain.Unload(domain);
                if (returnValue == (int) ReturnCodes.RestartDueToAvailableUpdate || returnValue == (int) ReturnCodes.RestartDueToConfigChange)
                    Main(args);
            }
            catch (Exception ex)
            {
                log.Error("An error occurred while running bootstrapped program", ex);
                Console.ReadLine();
            }
        }