public static string IsolateCallV1(PageContentHandler pHandler)
{
string name = Guid.NewGuid().ToString("N");
var domain = AppDomain.CreateDomain(name);
try
{
var proxy = (IAppEntry)domain.CreateInstanceAndUnwrap("AnfleCrawler.Common", "AnfleCrawler.Common.IsolateProxy");
string ret = (string)proxy.DoEntry(pHandler);
if (ret == null)
{
throw new InvalidOperationException("IsolateProxy");
}
return ret;
}
finally
{
//AppDomain不能即时卸载?不能在IDisposable中卸载? //App.LogInfo("IsolateCollect Unload {0}@{1}", domain.FriendlyName, AppDomain.CurrentDomain.FriendlyName);
//AppDomain.Unload(domain);
new JobTimer(state =>
{
try
{
var d = (AppDomain)state;
//if (d.IsFinalizingForUnload())
//{
// return;
//}
App.LogInfo("IsolateCollect Unload {0}", d.FriendlyName);
AppDomain.Unload(d);
}
catch (Exception ex)
{
App.LogError(ex, "IsolateCollect");
}
}, DateTime.Now.AddSeconds(20d)).Start(domain);
}
}