how to cancel or pause a task

how to cancel or pause a task

KM_Yotsuha
Advocate Advocate
480 Views
2 Replies
Message 1 of 3

how to cancel or pause a task

KM_Yotsuha
Advocate
Advocate

I have a plugin which takes 40 minites to finish running.How can I pause or cancel the task using buttons on a process form?

I konw Revit doesn't support muti-thread, is there any way to cancel or pause the work of a plugin?

0 Likes
Accepted solutions (1)
481 Views
2 Replies
Replies (2)
Message 2 of 3

jeremy_tammik
Alumni
Alumni
Accepted solution

I know Revit doesn't support muti-thread, is there any way to cancel or pause the work of a plugin?

 

No.

 

The Revit API is single-threaded, as you say, and completely event driven. Once Revit has called your event handler, you have to do your job and return control to Revit. It will not do anything else until you have returned control.

 

That said, you can implement an add-in that works in a modeless context. Then it can do its job in parallel with Revit. However, you have no access to the Revit API from the modeless context.

 

Next step: you can mix these two possibilities: implement an add-in that runs in a modeless context. So to speak, it is outside of Revit. Add an external event to that, and raise that event now and then when you need access to the Revit API. In your event handler, interact with Revit and return control to Revit. Continue working in you modeless state and continue raising your external event until the task is completed.

 

This is described in much detail and with numerous examples in The Building Coder topic group on Idling and External Events for Modeless Access and Driving Revit from Outside:

  

https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.28

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 3

KM_Yotsuha
Advocate
Advocate
thank you~
0 Likes