处置使用 MAF 创建的 AddIn (System.AddIn)
有谁知道如何处理使用 System.AddIn 创建的 AddIn。所有在线示例似乎都展示了如何轻松加载和使用插件,但没有一个示例展示了如何在它们存活后对其进行处理。我的问题是我在新进程中创建插件,但这些进程永远不会被垃圾收集,这显然是一个问题。
下面是一些示例代码来说明我的问题。假设用户从未退出此应用程序,而是创建了许多 ICalculator 实例。这些加载项进程如何被处理掉?
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);
}
}
Does anyone know how to dispose of AddIns created using System.AddIn. All the examples online seem to show how to easily load and use an addin, but none show how to dispose of them once they're alive. My Problem is I create addins in new processes, and these processes never get garbage collected, obviously a problem.
Below is some sample code illustrating my problem. Assume that the user never exits this application, but instead creates many instances of ICalculator. How do these addIn processes ever get disposed of?
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我设法找到了上述问题的解决方案,它利用了 AddInController 类及其关闭方法。现在看看我是否可以让它在我的应用程序中工作,而不仅仅是这个例子:
I managed to find a solution to the above problem, it's making use of the AddInController class and it's shutdown method. Now to see if I can get this to work in my application, not just this example:
你的解决方案对我不起作用。
由于您正在为您的外接程序创建一个新进程,因此您可以简单地
关闭外部进程
your solution didn't work for me.
Since you are creating a new process for your addin you can simply
the external process will shutdown