How to stop opening multiple instances of addin

How to stop opening multiple instances of addin

Anonymous
Not applicable
1,331 Views
7 Replies
Message 1 of 8

How to stop opening multiple instances of addin

Anonymous
Not applicable

Is there a way to stop opening multiple instances of add-in. In my revit add-in, the user can open multiple instances of the application by clicking the addin button again and again. I would like to know, how do I stop the user to click addon button for multiple times?

 

Appreciate any help.

Thank you.

0 Likes
Accepted solutions (1)
1,332 Views
7 Replies
Replies (7)
Message 2 of 8

jeremytammik
Autodesk
Autodesk
Accepted solution

That is not normal.

 

You are probably displaying a modeless form each time you run your external command.

 

Display a modal form instead, and life will be easier and safer.

 

I.e., use ShowDialog instead of Show.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 8

Anonymous
Not applicable

I changed Show method to ShowDialog and it worked. Thanks again @jeremytammik your constant support for revit-api community is admirable. Stay blessed.

 

- Ali

0 Likes
Message 4 of 8

Anonymous
Not applicable

Hi dear @jeremytammik ,

what if I need to work with modeless forms or want to create dockable panels

how can we prevent new windows from showing up while the first window is running

many thanks in advance

 

0 Likes
Message 5 of 8

RPTHOMAS108
Mentor
Mentor

Store a static variable, upon form loaded set it to true, upon form close set it to false.

 

In-between: Before opening form check static variable. 

Message 6 of 8

Anonymous
Not applicable

i did that but could not return it back to false to be able to run the form again

I found nice solution.

using registry to save the value and read write it from anywhere in the app

 

0 Likes
Message 7 of 8

jeremy_tammik
Alumni
Alumni

Congratulations on solving your task! However, I would call saving to the registry a 'not-so-nice' solution, since it sounds like total overkill for what you really need.

 

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

Kennan.Chen
Advocate
Advocate

Making the window object a singleton solves your problem. Further more you can use the .NET Mutex class to achieve a system-level singleton