# Subscribe to VisionPro Events

To subscribe to VisionPro events:

1. Subscribe to the event(s) in the Startup script.

   1. Get the object you want with GetInternalObject.
   2. Create an "eventHandler" tag in Tag Manager. This tag should be an object.
   3. Cast your lambda expression to the delegate type required for your event (CogChangedEventHandler in this case).

   4. Subscribe to the event of the object with the Event Handler.

          var toolblock = $System.GetInternalObject("Tasks.Task.Task.VisionProToolBlock1") as Cognex.VisionPro.ToolBlock.CogToolBlock;

          $eventHandler = (CogChangedEventHandler)((sender, e) =>
          	{
          		System.Diagnostics.Debug.WriteLine(e.StateFlags);
          	});

          toolblock.Changed += ($eventHandler);

2. Unsubscribe from the event in the OnShutdown script.

       toolblock.Changed -= ($eventHandler);