ARTICLE AD BOX
I have a Word VSTO plugin solution with other supporting projects inside the solution. I need to change the icon of the ribbon button based on the result of an async task. To do this I use ribbon.Invalidate(). This refreshes my ribbon and load the new icon. These are just buttons, created in ribbon XML.
I cannot integrate the ribbon.Invalidate() in to my button clicks in the Ribbon.cs as the button clicks mostly calls Async functions, or function that calls async functions - in other projects. So just after the button click, the function immediately returns and invalidates the ribbon, before the background running async function completes it's process.
I tried sending the ribbon object as a parameter in the the function, which runs the sync task and calling the Invalidate from there - in the finally statement of the function. It was a success in some cases, but tricky in some instances. But I can make it work.
My question is, is it okay to pass the ribbon as a parameter to the inside classes, or is there any better way?
Ribbon.cs buttonClick() { SomeClass.SomeFunction(ribbon) } SomeClass.cs SomeFunction(IRibbonUI ribbon) { try { //Async Process } finally { ribbon.Invalidate() } }