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