ELI5 Why to unsubscribe events on shutdown

ELI5 Why to unsubscribe events on shutdown

H.echeva
Advocate Advocate
244 Views
2 Replies
Message 1 of 3

ELI5 Why to unsubscribe events on shutdown

H.echeva
Advocate
Advocate

Hello,

 

I am watching a Revit API course and in one lesson he says that we should unsubscribe Onshutdown from the event that he created (document changed).

Can someone explain why this is necessary? If Revit is closed, it cannot longer run that code right?

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

ricaun
Advisor
Advisor
Accepted solution

Yes, you should unsubscribe in the Onshutdown, that's a good practice.

 

Before Revit finishes closing every application Onshutdown is called and at this time Revit still running anything could happen.

 

And imagine if you could load/unload an application with Revit open. If you do not unsubscribe, the event gonna stay forever in Revit until you close.

 

With the AppLoader you can load/unload an application with Revit open, and here is why you should unsubscribe in the Onshutdown.

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

Message 3 of 3

H.echeva
Advocate
Advocate
Thanks, I imagined there would be a good reason. Cheers
0 Likes