Best practice for AddIn command to be executed at regular interval?

Best practice for AddIn command to be executed at regular interval?

DynamicObjects
Advocate Advocate
660 Views
2 Replies
Message 1 of 3

Best practice for AddIn command to be executed at regular interval?

DynamicObjects
Advocate
Advocate

Hello

 

I have a webAPI running on a server with the following endpoint : http://api.myserver.com/HasJob 

I would like Inventor to poll this endpoint every 10 seconds in order to determine if there is a job for Inventor to do.

I have followed the examples in the SDK to create a C# AddIn that is loaded when Inventor starts.

Inventor.ApplicationEvents exposes many different events but I don't see a timer-based event. What would be the best-practice way for me to trigger my polling action every 10 seconds?

 

My idea so far it to :

  • add a handler for the .ApplicationEvents.OnReady event during the StandardAddInServer.Activate() method called when Inventor is loading addIns.
  • in my OnReadyEventHandler() set up a standard System.Windows.Forms Timer class to call my poll method. and set the interval to 10 seconds..

Is this considered to be best practice?

Regards

Dan

------------------------------------------------------------------------------------------------------------
Atkins Consultants Ltd UK
+19,000 staff (M&E, Civils, Structural, Geotechnical, Environmental and more)
0 Likes
661 Views
2 Replies
Replies (2)
Message 2 of 3

DynamicObjects
Advocate
Advocate
Just to add detail .. I am concerned about the timer event firing when the User/Inventor is in the middle of some action - I only want it to execute if Inventor is idle.
AFAIK Application.Ready relates only to initialisation, and this 2014 post (https://forums.autodesk.com/t5/inventor-customization/idle-event-in-autodesk-inventor/td-p/5397569) indicates Inventor api does not have an .Idle event back then.
Does anyone know if the api includes anything now to provide for this?
------------------------------------------------------------------------------------------------------------
Atkins Consultants Ltd UK
+19,000 staff (M&E, Civils, Structural, Geotechnical, Environmental and more)
0 Likes
Message 3 of 3

AlexKorzun
Autodesk
Autodesk

Hi,

 

You may consider using BackgroundWorker (https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.backgroundworker?view=netframework...) for your case.

For example, query your service in the worker thread and report progress to creator's thread when necessary.  ProgressChanged event will be handled when Inventor in not busy, and it is safe to use Inventor API in it. And yes, you don't even need a timer for scheduling in the worker thread.

 

Thank you,




Alex Korzun
Inventor-Revit Interop / Inventor-Fusion Interop / Inventor ETO
Autodesk, Inc.