c# - Dispose of AddIns created using MAF (System.AddIn) -
does know how dispose of addins created using system.addin. examples online seem show how load , use addin, none show how dispose of them once they're alive. problem create addins in new processes, , these processes never garbage collected, problem.
below sample code illustrating problem. assume user never exits application, instead creates many instances of icalculator. how these addin processes ever disposed of?
static void main(string[] args) { string addinroot = getexecutingdirectory(); // update cache files of pipeline segments , add-ins string[] warnings = addinstore.update(addinroot); // search 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 add-in runcalculator(calc); } }
i managed find solution above problem, it's making use of addincontroller class , it's shutdown method. see if can work in application, not example:
static void main(string[] args) { string addinroot = getexecutingdirectory(); string[] warnings = addinstore.update(addinroot); collection<addintoken> tokens = addinstore.findaddins(typeof(icalculatorhost), addinroot); while (true) { addintoken calctoken = choosecalculator(tokens); addinprocess addinprocess = new addinprocess(); icalculatorhost calc = calctoken.activate<icalculatorhost>(addinprocess, addinsecuritylevel.internet); // run add-in runcalculator(calc); // shutdown add-in when runcalculator method finishes executing addincontroller controller = addincontroller.getaddincontroller(calc); controller.shutdown(); } }
Comments
Post a Comment