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;
}