Load form from signal change

I am getting frustrated. I need to load a new form when a signal changes in the IRC5. I can not use the SignalBindingSource because I have to bind a visible control to it in order to see it change. And I can not get the standard signals to show my form. Here is a code example.

private void _sigSystemState_Changed(object sender, ABB.Robotics.Controllers.IOSystemDomain.SignalChangedEventArgs e)

//Update the GUI if the signal GI_001 changes in the controller

{

CalibrationView2 _CalibrationView2 = new CalibrationView2();

_CalibrationView2.ShowMe(this);

}

private void button1_Click(object sender, EventArgs e)

{

CalibrationView2 _CalibrationView2 = new CalibrationView2();

_CalibrationView2.ShowMe(this);

}

The button example works fine but the SignalBindingSouces change event is on another thread? Exact error: “Controls created on one thread cannot be parented to a control on a different thread.”

So how do I have a simple signal show a new view/form?

Shane

Hi Shane,

I tend to over-explained the stuff … please let me know if I am goind to much in detail, I will do my best in next posts :). So here it comes

Only the UI threads are allow to execute code that will modify the user interface.

Inside a Teach Pendant application, there is only one UI thread running at all time. All the events coming for the IRC5 (either by the BindingSource or a Changed event of a RapidData or Signal) comes in a different thread. Hence, what we need to do is to call the UI thread from your executing thread. Here it comes some sample code:

void MySignal_Changed(object sender, SignalChangedEventArgs e)

{

// We are running in a non-ui thread, so it is not allowed to make changes in the user interface. Lets invoke the UI thread

// In order to invoke the UI thread, we need to use a control that was created in the UI thread.

// In most of the cases, the form in which you are runnning was created in the UI tread, so lets use that one.

// We will assume that ‘this’ makes reference to the form

this.Invoke(new SignalChangedEventHandler(MySignal_Changed_UI), sender, e);

}

void MySignal_Changed_UI(object sender, SignalChangedEventArgs e)

{

// This code will be running in the UI thread as long as it comes from an invoke

// Here, you can open your view

CalibrationView2 _CalibrationView2 = new CalibrationView2();

_CalibrationView2.ShowMe(this);

}

In your case, the method _CalibrationView2.ShowMe(this) is tryting to create and display a Form. It does not work in the method “_sigSystemState_Changed” because this in called by the SignalBindingSource; the other one because a method that is called for a Click event, it is executed inside a UI thread already (the event is UI driven as such).
Hope this helps to explain the behaviour.

Saludos … Carlos

Carlos,

That is exactly what I needed! Thanks for taking the time and effort to, as in your words, over-explain stuff. It really is appreciated.

I will try this this morning,
Shane