Пример #1
0
		private void initAppDomain()
		{
			var pathToAssembly = resolvePath(Settings.Default.WorkerAssemblyPath);

			if (String.IsNullOrEmpty(pathToAssembly))
				throw new FileNotFoundException("Could not locate the file to load.", 
					Settings.Default.WorkerAssemblyPath);

			var domainSetup = new AppDomainSetup { PrivateBinPath = pathToAssembly };

			_domain = AppDomain.CreateDomain("Domain_" + Guid.NewGuid(), null, domainSetup);

			_marshalledRef = (Performer)_domain.CreateInstanceFromAndUnwrap(
				pathToAssembly, Settings.Default.WorkerClassName);

			_log.Info("Initialized application domain.");
			_log.DebugFormat("AppDomain Name: {0}", _domain.FriendlyName);
		}
Пример #2
0
		private bool releaseAppDomain()
		{
			if (_domain == null) return true;

			var retries = 0;
			while(retries++ <= Settings.Default.RetriesToUnloadAppDomain)
			{
				try
				{
					_log.Info("Attempting to release application domain.");

					if (_domain != null)
					{
						_log.DebugFormat("Domain Name: {0}", _domain.FriendlyName);
						AppDomain.Unload(_domain);
					}

					_marshalledRef = null;
					_domain = null;

					_log.Info("Succeeded.");

					return true;
				}
				catch (AppDomainUnloadedException appDomainUnloadedException)
				{
					_log.InfoFormat("Could not release domain. Retrying {0} out of {1}...",
						retries, Settings.Default.RetriesToUnloadAppDomain);

					_log.Debug("Exception Information", appDomainUnloadedException);
				}
			}
				
			return false;
		}