Thank you all for your responses. I have tried 3 different solutions all to no success.
- I tried running 1 idling event with block if statements just to perform different actions based on some state variables.
- This fails because one of my functions also ends up giving Revit the opportunity to idle. This causes a never ending idling loop.
- I retried subscribing to a new handler inside of handler A.
- This fails with an error "Cannot subscribe to an event during execution of that event". I am attempting to subscribe to a different handler function with code in the form of below.
-
public async void OnIdlingA(object sender, IdlingEventArgs e)
{
Autodesk.Revit.UI.UIApplication uiapp = sender as
Autodesk.Revit.UI.UIApplication;
Debug.Assert(null != uiapp,
"expected a valid Revit application instance");
if (uiapp != null)
{
uiapp.Idling -= OnIdlingA;
uiapp.Idling += new
EventHandler<Autodesk.Revit.UI.Events.IdlingEventArgs>
(OnIdlingB);
await FuncA();
}
}
- Finally, I tried the Idling Queue service
- This also fails due the the fact that I am getting extra idling events while my functions are running causing the execution to dive into the idling functions before finishing the current function.
If I step back from all the details of my implementation, my problem is really not too complicated. I just wish I could run the Execute function of IExternalCommand like below.
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
Object1 obj1 = new Object1(commandData)
await obj1.func1;
await obj1.func2;
obj1.func3; //THIS IS THE ONLY REVIT INTERACTION
return Autodesk.Revit.UI.Result.Succeeded;
}
This doesn't work because I can not make the Execute function async but this is the theory. Not being able to await func1 and func2 is what is causing me to dive so deep into idling events. Func1 and Func2 have nothing to do with Revit.
Func1 calls a web server to do authentication in a webview
Func2 calls a web server to download Revit files
Func3 opens those files and uses that data to manipulate the current document.
Thank you all for the guidance