// Find a free AppDomain, creating one if necessary AppDomainStructure GetFreeAppDomain() { // use only the current domain? if (loadAllScriptsIntoCurrentDomain) { // existing? lock (m_appDomainLock) { if (currentAD != null) { return(currentAD); } } // create a new one then lock (m_appDomainLock) { currentAD = new AppDomainStructure { CurrentAppDomain = AppDomain.CurrentDomain }; AppDomain.CurrentDomain.AssemblyResolve += m_scriptEngine.AssemblyResolver.OnAssemblyResolve; return(currentAD); } } // use a single script domain? if (loadAllScriptsIntoOneDomain) { lock (m_appDomainLock) { if (currentAD == null) { // Create a new current AppDomain currentAD = new AppDomainStructure { CurrentAppDomain = PrepareNewAppDomain() }; } return(currentAD); } } // multiple script domains then lock ( m_appDomainLock) { // Current full? if (currentAD != null && currentAD.ScriptsLoaded >= maxScriptsPerAppDomain) { // Add it to AppDomains list and empty current appDomains.Add(currentAD); currentAD = null; } // NO or New current if (currentAD == null) { // Create a new current AppDomain currentAD = new AppDomainStructure { CurrentAppDomain = PrepareNewAppDomain() }; } return(currentAD); } }
// Unload appdomains that are full and have only dead scripts void UnloadAppDomains() { lock (m_appDomainLock) { // Go through all foreach ( AppDomainStructure ads in appDomains.Where(ads => ads.ScriptsLoaded <= ads.ScriptsWaitingUnload)) { // Remove from internal list appDomains.Remove(ads); try { // Unload if (ads != null) { AppDomain.Unload(ads.CurrentAppDomain); if (currentAD != null) { if (ads.CurrentAppDomain == currentAD.CurrentAppDomain) { currentAD = null; } } } } catch { } if (ads != null) { ads.CurrentAppDomain = null; } } if (currentAD != null) { if (currentAD.ScriptsLoaded <= currentAD.ScriptsWaitingUnload) { if (currentAD.CurrentAppDomain.Id != AppDomain.CurrentDomain.Id) //Don't kill the current app domain! { try { // Unload AppDomain.Unload(currentAD.CurrentAppDomain); } catch { } currentAD.CurrentAppDomain = null; currentAD = null; } } } } }
// Find a free AppDomain, creating one if necessary private AppDomainStructure GetFreeAppDomain() { if (loadAllScriptsIntoCurrentDomain) { if (currentAD != null) { return(currentAD); } else { lock (m_appDomainLock) { currentAD = new AppDomainStructure { CurrentAppDomain = AppDomain.CurrentDomain }; AppDomain.CurrentDomain.AssemblyResolve += m_scriptEngine.AssemblyResolver.OnAssemblyResolve; return(currentAD); } } } lock (m_appDomainLock) { if (loadAllScriptsIntoOneDomain) { if (currentAD == null) { // Create a new current AppDomain currentAD = new AppDomainStructure { CurrentAppDomain = PrepareNewAppDomain() }; } } else { // Current full? if (currentAD != null && currentAD.ScriptsLoaded >= maxScriptsPerAppDomain) { // Add it to AppDomains list and empty current lock (m_appDomainLock) { appDomains.Add(currentAD); } currentAD = null; } // No current if (currentAD == null) { // Create a new current AppDomain currentAD = new AppDomainStructure { CurrentAppDomain = PrepareNewAppDomain() }; } } } return(currentAD); }
public IScript LoadScript(string FileName, string TypeName, out AppDomain ad) { // Find next available AppDomain to put it in AppDomainStructure FreeAppDomain = GetFreeAppDomain(); IScript mbrt = (IScript) FreeAppDomain.CurrentAppDomain.CreateInstanceFromAndUnwrap( FileName, TypeName); FreeAppDomain.ScriptsLoaded++; ad = FreeAppDomain.CurrentAppDomain; return(mbrt); }
// Unload appdomains that are full and have only dead scripts private void UnloadAppDomains() { lock (m_appDomainLock) { // Go through all foreach (AppDomainStructure ads in appDomains) { // Not current AppDomain // Is number of unloaded bigger or equal to number of loaded? if (ads.ScriptsLoaded <= ads.ScriptsWaitingUnload) { // Remove from internal list appDomains.Remove(ads); try { // Unload AppDomain.Unload(ads.CurrentAppDomain); } catch { } if (ads.CurrentAppDomain == currentAD.CurrentAppDomain) { currentAD = null; } ads.CurrentAppDomain = null; } } if (currentAD != null) { if (currentAD.ScriptsLoaded <= currentAD.ScriptsWaitingUnload) { try { // Unload AppDomain.Unload(currentAD.CurrentAppDomain); } catch { } currentAD.CurrentAppDomain = null; currentAD = null; } } } }
// Find a free AppDomain, creating one if necessary private AppDomainStructure GetFreeAppDomain() { lock (getLock) { // Current full? if (currentAD != null && currentAD.ScriptsLoaded >= maxScriptsPerAppDomain) { // Add it to AppDomains list and empty current appDomains.Add(currentAD); currentAD = null; } // No current if (currentAD == null) { // Create a new current AppDomain currentAD = new AppDomainStructure(); currentAD.CurrentAppDomain = PrepareNewAppDomain(); } return(currentAD); } }
// Find a free AppDomain, creating one if necessary private AppDomainStructure GetFreeAppDomain() { if (loadAllScriptsIntoCurrentDomain) { if (currentAD != null) return currentAD; else { lock (m_appDomainLock) { currentAD = new AppDomainStructure { CurrentAppDomain = AppDomain.CurrentDomain }; AppDomain.CurrentDomain.AssemblyResolve += m_scriptEngine.AssemblyResolver.OnAssemblyResolve; return currentAD; } } } lock (m_appDomainLock) { if (loadAllScriptsIntoOneDomain) { if (currentAD == null) { // Create a new current AppDomain currentAD = new AppDomainStructure { CurrentAppDomain = PrepareNewAppDomain() }; } } else { // Current full? if (currentAD != null && currentAD.ScriptsLoaded >= maxScriptsPerAppDomain) { // Add it to AppDomains list and empty current lock (m_appDomainLock) { appDomains.Add(currentAD); } currentAD = null; } // No current if (currentAD == null) { // Create a new current AppDomain currentAD = new AppDomainStructure { CurrentAppDomain = PrepareNewAppDomain() }; } } } return currentAD; }
// Unload appdomains that are full and have only dead scripts private void UnloadAppDomains() { lock (m_appDomainLock) { // Go through all #if (!ISWIN) foreach (AppDomainStructure ads in appDomains) { if (ads.ScriptsLoaded <= ads.ScriptsWaitingUnload) { // Remove from internal list appDomains.Remove(ads); try { // Unload if (ads != null) AppDomain.Unload(ads.CurrentAppDomain); } catch { } if (ads.CurrentAppDomain == currentAD.CurrentAppDomain) currentAD = null; ads.CurrentAppDomain = null; } } #else foreach (AppDomainStructure ads in appDomains.Where(ads => ads.ScriptsLoaded <= ads.ScriptsWaitingUnload)) { // Remove from internal list appDomains.Remove(ads); try { // Unload if (ads != null) AppDomain.Unload(ads.CurrentAppDomain); } catch { } if (ads.CurrentAppDomain == currentAD.CurrentAppDomain) currentAD = null; ads.CurrentAppDomain = null; } #endif if (currentAD != null) { if (currentAD.ScriptsLoaded <= currentAD.ScriptsWaitingUnload) { if (currentAD.CurrentAppDomain.Id != AppDomain.CurrentDomain.Id) //Don't kill the current app domain! { try { // Unload AppDomain.Unload(currentAD.CurrentAppDomain); } catch { } currentAD.CurrentAppDomain = null; currentAD = null; } } } } }
// Unload appdomains that are full and have only dead scripts private void UnloadAppDomains() { lock (m_appDomainLock) { // Go through all foreach (AppDomainStructure ads in appDomains) { // Not current AppDomain // Is number of unloaded bigger or equal to number of loaded? if (ads.ScriptsLoaded <= ads.ScriptsWaitingUnload) { // Remove from internal list appDomains.Remove(ads); try { // Unload AppDomain.Unload(ads.CurrentAppDomain); } catch { } if (ads.CurrentAppDomain == currentAD.CurrentAppDomain) currentAD = null; ads.CurrentAppDomain = null; } } if (currentAD != null) { if (currentAD.ScriptsLoaded <= currentAD.ScriptsWaitingUnload) { if (currentAD.CurrentAppDomain.Id != AppDomain.CurrentDomain.Id)//Don't kill the current app domain! { try { // Unload AppDomain.Unload (currentAD.CurrentAppDomain); } catch { } currentAD.CurrentAppDomain = null; currentAD = null; } } } } }
// Find a free AppDomain, creating one if necessary AppDomainStructure GetFreeAppDomain() { // use only the current domain? if (loadAllScriptsIntoCurrentDomain) { // existing? lock (m_appDomainLock) { if (currentAD != null) return currentAD; } // create a new one then lock (m_appDomainLock) { currentAD = new AppDomainStructure {CurrentAppDomain = AppDomain.CurrentDomain}; AppDomain.CurrentDomain.AssemblyResolve += m_scriptEngine.AssemblyResolver.OnAssemblyResolve; return currentAD; } } // use a single script domain? if (loadAllScriptsIntoOneDomain) { lock (m_appDomainLock) { if (currentAD == null) { // Create a new current AppDomain currentAD = new AppDomainStructure { CurrentAppDomain = PrepareNewAppDomain () }; } return currentAD; } } // multiple script domains then lock( m_appDomainLock) { // Current full? if (currentAD != null && currentAD.ScriptsLoaded >= maxScriptsPerAppDomain) { // Add it to AppDomains list and empty current appDomains.Add (currentAD); currentAD = null; } // NO or New current if (currentAD == null) { // Create a new current AppDomain currentAD = new AppDomainStructure { CurrentAppDomain = PrepareNewAppDomain () }; } return currentAD; } }
// Find a free AppDomain, creating one if necessary private AppDomainStructure GetFreeAppDomain() { lock (getLock) { // Current full? if (currentAD != null && currentAD.ScriptsLoaded >= maxScriptsPerAppDomain) { // Add it to AppDomains list and empty current appDomains.Add(currentAD); currentAD = null; } // No current if (currentAD == null) { // Create a new current AppDomain currentAD = new AppDomainStructure(); currentAD.CurrentAppDomain = PrepareNewAppDomain(); } return currentAD; } }