There’s two main situations in which code that modifies the file runs:
As a response to a UI event, this always happens outside of solutions because while a solution runs the UI is not processing messages.
As a part of a scheduled solution.
I assume you need #2
Inside your RunScript or SolveInstance or whatever method, get the document that contains your component. In a C# script that’s just GrasshopperDocument, inside a compiled GH_Component class that’s by calling the OnPingDocument() method and making sure you didn’t get null in return. Then you schedule a solution on that document, usually picking a short interval. Something between 5 to 50 milliseconds for example. You also must provide a schedule callback. This callback method will be called whenever the next solution kicks off, even if it is way earlier than your schedule request. Inside the callback you are allowed to make all the changes you want, add objects, delete objects, modify values, add or remove connections etc.
It’s too early to start printing stuff, the solution isn’t really running yet. Also your component is not automatically expired, so there’s no guarantee it will run at all in this solution.
Use RhinoApp.WriteLine() if you want to test code like this, that always works.