using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pit.Application.Scheduler
{
public class AppDomainLoader
{
///
/// 加载应用程序,获取相应实例
///
///
///
///
///
public static BaseJob Load(string dllPath, string classPath, out AppDomain appDomain)
{
AppDomainSetup setup = new AppDomainSetup();
if (System.IO.File.Exists($"{dllPath}.config"))
setup.ConfigurationFile = $"{dllPath}.config";
setup.ShadowCopyFiles = "true";
setup.ApplicationBase = System.IO.Path.GetDirectoryName(dllPath);
appDomain = AppDomain.CreateDomain(System.IO.Path.GetFileName(dllPath), null, setup);
AppDomain.MonitoringIsEnabled = true;
BaseJob obj = (BaseJob)appDomain.CreateInstanceFromAndUnwrap(dllPath, classPath);
return obj;
}
///
/// 卸载应用程序
///
///
public static void UnLoad(AppDomain appDomain)
{
AppDomain.Unload(appDomain);
appDomain = null;
}
}
}