It’s not clear what issue you are facing. If you just want to process time/position whenever the program pointer changes, below would be a cleaner approach-
public delegate void ChangePosition_Delegate(string input);
public class MonitorProgramPosition
{
private Controller _robot;
private ChangePosition_Delegate CP_Delegate = delegate (string input) { Console.WriteLine(input); }; // Just print input to console for testing
// Event handler
public void PositionChangeEvent(object sender, ProgramPositionEventArgs e)
{
CP_Delegate(e.Time.Millisecond.ToString());
}
// Connect to controller and subscribe to event
public MonitorProgramPosition(Guid robotGUID)
{
_robot = new Controller(robotGUID);
_robot.Rapid.GetTask("T_ROB1").ProgramPointerChanged += PositionChangeEvent;
}
// Just keeps program open till any button is pressed
public void Wait()
{
Console.ReadLine();
_robot.Rapid.GetTask("T_ROB1").ProgramPointerChanged -= PositionChangeEvent;
_robot.Logoff();
_robot.Dispose();
}
}
class Program
{
static void Main(string[] args)
{
var ppMonitor = new MonitorProgramPosition(Guid.Parse(<YourRobotGUID>));
ppMonitor.Wait();
}
}