有誰知道如何處理使用System.AddIn創建的AddIns。所有在線示例似乎都顯示瞭如何輕鬆加載和使用外掛程序,但是沒有一個顯示如何在它們還活着時處置它們。我的問題是我在新進程中創建插件,並且這些進程永遠不會收集垃圾,顯然是一個問題。處理使用MAF創建的AddIns(System.AddIn)
下面是說明我的問題的一些示例代碼。假設用戶永遠不會退出此應用程序,而是創建了許多ICalculator實例。這些addIn進程如何被處置?
static void Main(string[] args)
{
string addInRoot = GetExecutingDirectory();
// Update the cache files of the pipeline segments and add-ins
string[] warnings = AddInStore.Update(addInRoot);
// search for add-ins of type ICalculator
Collection<AddInToken> tokens = AddInStore.FindAddIns(typeof(ICalculatorHost), addInRoot);
string line = Console.ReadLine();
while (true)
{
AddInToken calcToken = ChooseCalculator(tokens);
AddInProcess addInProcess = new AddInProcess();
ICalculatorHost calc = calcToken.Activate<ICalculatorHost>(addInProcess, AddInSecurityLevel.Internet);
// run the add-in
RunCalculator(calc);
}
}
哦,一些額外的信息。我還在我的HostViewAdapter類中保留對合同句柄的引用,這似乎仍然沒有成功。 – 2010-10-07 10:47:47