How to dispose C# objects from zero touch nodes at the end of a script

I have a zero touch dynamo package that creates a bunch of c# objects. I want to dispose these objects and the processes they are tied to at the end of the script. Is there an event that can be triggered at the end of a dynamo script? Any ideas/suggestions would be appreciated!


You can find more information here about disposing:

Appreciate the link. The issue I am facing is I want to call these dispose statements at the end of a dynamo script. Hence why I am curious if an event can be triggered by the end of a dynamo script.

Why do you want that? You hand the objects over to Dynamo, your code is not aware of it anymore.

I’m using dynamo to connect with different softwares on my computer. The idea is very similiar to pipe operations (Pipe Operations). At the end of the script I want to close the pipeline so I don’t have any outstanding processes running / threads open. This is very simple to do if there is an event that is triggerable at the end of the script. Grasshopper API has something easy to trigger, didn’t know if it was possible for Dynamo.

Ah ok. I am not sure if it is possible, there are events that the Dynamo environment fires. Maybe that will help you. I can’t find an example but here is an example how to subscribe an event when a user adds a node to the canvas.

From ZT nodes you are somewhat limited intentionally, but you can use:
an example test using it - you will want to reference DynamoServices nuget.

1 Like

BEAUTIFUL! Thank you :slight_smile: Love this forum.

actually @normnoe - I don’t think this is the best approach - just implement IDisposable on the objects you return, the Dynamo VM will call dispose on them when it is done with those objects (they are no longer in the graph) - probably when the next execution starts. It depends on your exact use case of course.


I will give this approach a go and relay back on whether it worked! This would be much simpler I agree. Thanks so much.