0

I have a dynamic menu button in our custom VSTO ribbon. I am loading content to it at runtime. That process is working fine. Dynamic drop down is creating fine. this is the code.

In Ribbon.xml

<dynamicMenu id="RunWorkflow" size="large" getLabel="GetLabel" getImage="GetImage" getScreentip="GetScreenTip" getSupertip="GetSuperTip" keytip="EJ" getContent="GetWorkflows"/>

In Ribbon.cs

 public string GetWorkflows(Office.IRibbonControl control)
 {
 string menuItem = "<menu xmlns=\"http://schemas.microsoft.com/office/2009/07/customui\">";
 List<string> workflows = FetchWorkflows(); //there were few lines above for fetch workflows. This part works fine.
 if (workflows != null && workflows.Count > 0)
 {
 int count = 1;
 foreach (string workflowPath in workflows)
 {
 string[] paths = workflowPath.Split('/');
 var name = paths[paths.Count() - 1].Replace(".abc_workflow", "");
 var id = "Workflows" + count.ToString();
 menuItem = menuItem + "<button id=\"" + id + "\" label=\"" + name + "\" onAction=\"TPS_WorkflowProcessing\" getImage=\"GetImage\" tag=\"" + workflowPath + "\"/>";
 count++;
 }
 menuItem = menuItem + "</menu>";
 } 
 return menuItem;
 }
 public void TPS_WorkflowProcessing(Office.IRibbonControl control)
 {
 string workflowPath = control.Tag;
 using (MyApplication app = new MyApplication())
 { 
 app.Tools.RunDocumentProcessing(workflowPath);
 }
 }

On Tools.cs

 public void RunDocumentProcessing(string workflowPath)
 { 
 if (this.IsActiveDocumentReady)
 {
 string outputFileExtesion = Constants.EXTENTION_DOCX;
 this.RunJob(workflowPath, outputFileExtesion);
 }
 }
 private async void RunJob(string workflowPath, string outputExtension)
 {
 //Noting from inside is getting executed
 }

In the RunJob() function, I am sending multiple async server requests. So I have to make it async.

This code executes fine when run via Visual Studio. But when we build the installer and run with it, it is executing up to string outputFileExtesion = Constants.EXTENTION_DOCX; line on Tools.RunDocumentProcessing function. The RunJob() is not reaching. Why is that? How to fix this?

jonrsharpe
123k31 gold badges278 silver badges489 bronze badges
asked Nov 12, 2025 at 11:55
4
  • 3
    using (MyApplication app = new MyApplication()) will dispose app as soon as RunJob hands control back to the caller, which is when it hits the first await. Could this be the problem? You probably need to make everything async up to GetWorkflows. Commented Nov 12, 2025 at 17:07
  • ^^ using (MyApplication app = new MyApplication()) looks kind of suspicious to me in itself, to start with. Commented Nov 13, 2025 at 12:06
  • 1
    Also: private async void RunJob(string workflowPath, string outputExtension) this cannot be awaited. As a rule of thumb: async void is OK for event handlers, only (with very very few exceptions). Which means, I share Klaus' view on this - it needs to be "async all the way". Commented Nov 13, 2025 at 12:08
  • 1
    That said, if this happens to need to comply to a non-async API but itself must be async, then you need to find a safe way to block execution and wait for the async to complete. That defeats the asyncness, yes. But it will make the system operational. Commented Nov 14, 2025 at 7:22

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.