卸载AppDomain会导致程序崩溃

时间:2013-09-07 10:35:02

标签: c# appdomain

我创建了一个新的AppDomain => NewAppDomain

当我尝试卸载NewAppDomain时发生异常: “LocalDataStoreSlot存储已被释放。”,我的程序崩溃了。 为什么会发生异常?

一些代码:

public class ActivatedAddIn : DisposableClass
{
    public AppDomain AppDomain { get; internal set; }

    internal IBaseAddInApp Proxy { get;  set; }

    public void Shutdown()
    {
      Dispose();
    }

    public void Dispose()
    {
        //Here the crash :((( 
        AppDomain.Unload(AppDomain);
        AppDomain = null;
        Proxy = null;
        GC.WaitForPendingFinalizers();
        GC.Collect();

    }
}

关于加载项的窗口关闭事件:

ActivatedAddIn runnedAddIn = RunnedAddIns.FirstOrDefault(item => item.ActivatedAddIn.Proxy.RunnedId == runnedAddInId);
if(runnedAddIn == null) return;
RunnedAddIns.Remove(runnedAddIn);
runnedAddIn.ShutdownAddIn();

0 个答案:

没有答案