fitSharp.Machine.Application.Shell.RunInNewDomain C# (CSharp) Method

RunInNewDomain() static private method

static private RunInNewDomain ( AppDomainSetup appDomainSetup, IList commandLineArguments ) : int
appDomainSetup System.AppDomainSetup
commandLineArguments IList
return int
        static int RunInNewDomain(AppDomainSetup appDomainSetup, IList<string> commandLineArguments)
        {
            if (string.IsNullOrEmpty(appDomainSetup.ApplicationBase)) {
                appDomainSetup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
            }
            var newDomain = AppDomain.CreateDomain("fitSharp.Machine", null, appDomainSetup);
            int result;
            try {
                var remoteShell = (Shell) newDomain.CreateInstanceAndUnwrap(
                                              Assembly.GetExecutingAssembly().GetName().Name,
                                              typeof (Shell).FullName);
                result = remoteShell.RunInCurrentDomain(commandLineArguments);
            }
            finally {
                // avoid deadlock on Unload
                new Action<AppDomain>(AppDomain.Unload).BeginInvoke(newDomain, null, null);
            }
            return result;
        }