/// <summary> /// Runs the assembly with the specified arguments.xit /// </summary> /// <param name="workingDirectory">The working directory.</param> /// <param name="environmentVariables">The environment variables.</param> /// <param name="args">The main arguments.</param> /// <param name="logger">The logger.</param> /// <returns>System.Int32.</returns> public int Run(string workingDirectory, Dictionary <string, string> environmentVariables, string[] args, IServerLogger logger) { lock (disposingLock) { if (isDisposed) { logger.OnLog("Error, server is being shutdown, cannot run Compiler", ConsoleColor.Red); return(1); } } AppDomainShadow shadowDomain = null; try { shadowDomain = GetOrNew(IsCachingAppDomain); return(shadowDomain.Run(workingDirectory, environmentVariables, args, logger)); } finally { if (shadowDomain != null) { shadowDomain.EndRun(); if (!IsCachingAppDomain) { shadowDomain.Dispose(); } } } }
/// <summary> /// Get or create a new <see cref="AppDomainShadow"/>. /// </summary> /// <returns></returns> private AppDomainShadow GetOrNew(bool useCache) { lock (appDomainShadows) { foreach (var appDomainShadow in appDomainShadows) { if (appDomainShadow.TryLock()) { Console.WriteLine("Use cached AppDomain {0}", appDomainShadow.Name); return(appDomainShadow); } } var newAppDomainName = Path.GetFileNameWithoutExtension(mainAssemblyPath) + "#" + appDomainShadows.Count; Console.WriteLine("Create new AppDomain {0}", newAppDomainName); var newAppDomain = new AppDomainShadow(newAppDomainName, mainAssemblyPath, nativeDllsPathOrFolderList.ToArray()); newAppDomain.TryLock(); if (useCache) { appDomainShadows.Add(newAppDomain); } return(newAppDomain); } }
/// <summary> /// Runs the assembly with the specified arguments.xit /// </summary> /// <param name="args">The main arguments.</param> /// <param name="logger">The logger.</param> /// <returns>System.Int32.</returns> public int Run(string[] args, IServerLogger logger) { AppDomainShadow shadowDomain = null; try { shadowDomain = GetOrNew(IsCachingAppDomain); return(shadowDomain.Run(args, logger)); } finally { if (shadowDomain != null) { shadowDomain.EndRun(); if (!IsCachingAppDomain) { shadowDomain.Dispose(); } } } }
/// <summary> /// Get or create a new <see cref="AppDomainShadow"/>. /// </summary> /// <returns></returns> private AppDomainShadow GetOrNew(bool useCache) { lock (appDomainShadows) { var newAppDomainName = Path.GetFileNameWithoutExtension(mainAssemblyPath) + "#" + appDomainShadows.Count; while (true) { foreach (var appDomainShadow in appDomainShadows) { if (appDomainShadow.TryLock()) { Console.WriteLine("Use cached AppDomain {0}", appDomainShadow.Name); return(appDomainShadow); } } if (appDomainShadows.Count < maximumConcurrentAppDomain) { break; } else { // We should better use notify instead Thread.Sleep(200); } } Console.WriteLine("Create new AppDomain {0}", newAppDomainName); var newAppDomain = new AppDomainShadow(newAppDomainName, mainAssemblyPath, nativeDllsPathOrFolderList.ToArray()); newAppDomain.TryLock(); if (useCache) { appDomainShadows.Add(newAppDomain); } return(newAppDomain); } }
/// <summary> /// Get or create a new <see cref="AppDomainShadow"/>. /// </summary> /// <returns></returns> private AppDomainShadow GetOrNew(bool useCache) { lock (appDomainShadows) { var newAppDomainName = Path.GetFileNameWithoutExtension(mainAssemblyPath) + "#" + appDomainShadows.Count; while (true) { foreach (var appDomainShadow in appDomainShadows) { if (appDomainShadow.TryLock()) { Console.WriteLine("Use cached AppDomain {0}", appDomainShadow.Name); return appDomainShadow; } } if (appDomainShadows.Count < maximumConcurrentAppDomain) { break; } else { // We should better use notify instead Thread.Sleep(200); } } Console.WriteLine("Create new AppDomain {0}", newAppDomainName); var newAppDomain = new AppDomainShadow(newAppDomainName, mainAssemblyPath, nativeDllsPathOrFolderList.ToArray()); newAppDomain.TryLock(); if (useCache) { appDomainShadows.Add(newAppDomain); } return newAppDomain; } }
/// <summary> /// Get or create a new <see cref="AppDomainShadow"/>. /// </summary> /// <returns></returns> private AppDomainShadow GetOrNew(bool shadowCache, bool appdomainCache) { lock (appDomainShadows) { foreach (var appDomainShadow in appDomainShadows) { if (appDomainShadow.ShadowCache == shadowCache && appDomainShadow.TryLock()) { Console.WriteLine("Use cached AppDomain {0}", appDomainShadow.Name); return appDomainShadow; } } var newAppDomainName = Path.GetFileNameWithoutExtension(mainAssemblyPath) + "#" + appDomainShadows.Count; Console.WriteLine("Create new AppDomain {0}", newAppDomainName); var newAppDomain = new AppDomainShadow(newAppDomainName, mainAssemblyPath, shadowCache, nativeDllsPathOrFolderList.ToArray()); newAppDomain.TryLock(); if (appdomainCache) { appDomainShadows.Add(newAppDomain); } return newAppDomain; } }