C# Form Button Error

Dear Dynamo community

I made a button to select elements to rotate them at their location.
The second time i reclick on the button the dynamo freezes and i get an error like this:
Starting a transaction from an external application running outside of API context is not allowed.

I tried to look after this problem, and found that i should use ExternalEvents.
Can someone tell me what does that mean and how to use it? I couldn’t find an understandable reading about it.

It’s a zerotouch node.

Thank you!