Reputation: 25038
I have a method myobj_EndInteractionEvt that is executed when an event occurs
In main class I register like:
//on main class register method passing args like
lo.myobj.EndInteractionEvt += (s, args) => updateInteraction(lo.myobj_EndInteractionEvt(s, args));
//this is called when finish executin "lo.myobj_EndInteractionEvt"
public void updateInteraction(AOItour tour)
{
Console.WriteLine(tour.StateOfAOItour );
ClearMsg();
etc...
}
Inside myobj class I call myobj_EndInteractionEvt which returns an object AOItour
internal AOItour myobj_EndInteractionEvt(vtkObject losender, vtkObjectEventArgs e)
{
//do stuff and return AOItour
return AOItour;
}
this works as it is needed (mostly because I am working on vtk and this needs to use lots of callbacks), the issue comes as myobj has an other callback angleEndInteractionEvt that updates the AOItour internally
public void angleEndInteractionEvt(vtkObject sender, vtkObjectEventArgs e) {
//AOItour has been modified, so i would like to call own "myobj_EndInteractionEvt"
// so I can pass
// modified AOItour to it and then myobj_EndInteractionEvt would return AOI to
// updateInteraction
}
How to call callback myobj_EndInteractionEvt at the end angleEndInteractionEvt?
I have tried
public void angleEndInteractionEvt(vtkObject sender, vtkObjectEventArgs e) {
//some stuff
myobj_EndInteractionEvt(sender,e);
}
And it correctly goes to myobj_EndInteractionEvt but the issue is after that execution, program returns to angleEndInteractionEvt and does not go updateInteraction How to do that?
Upvotes: 0
Views: 183
Reputation: 34489
You'll need to trigger the Event that you've hooked up to. It's a little difficult understanding you're structure but typically you'd this in the class where you're event has been defined:
public class MyObj
{
public void angleEndInteractionEvt(vtkObject sender, vtkObjectEventArgs e) {
// Do stuff
if(EndInteractionEvt != null) {
EndInteractionEvt(sender, e);
}
}
}
Typically however sender should be this - the instance that triggered the event.
At this point the following line will kick into play:
lo.myobj.EndInteractionEvt += (s, args) => updateInteraction(lo.myobj_EndInteractionEvt(s, args));
Firstly your myobj_EndInteractionEvt method is going to be called which should return the AOITour.
internal AOItour myobj_EndInteractionEvt(vtkObject losender, vtkObjectEventArgs e)
{
//do stuff and return AOItour
return AOItour;
}
The result of this should then get passed into updateInteraction that I've listed below so you're logging should now kick in.
public void updateInteraction(AOItour tour)
{
Console.WriteLine(tour.StateOfAOItour );
ClearMsg();
etc...
}
What might be better and a little more readable (if they're defined on the same object) is to instead simply do:
public void angleEndInteractionEvt(vtkObject sender, vtkObjectEventArgs e) {
// Do stuff
this.myobj_EndInteractionEvt(sender, e);
if(EndInteractionEvt != null) {
EndInteractionEvt(sender, e);
}
}
Upvotes: 1
Reputation: 3352
myobj_EndInteractionEvt
is a method, not an event. Instead of calling myobj_EndInteractionEvt(sender,e);
directly, you need to trigger the event that calls it in your main class. So change angleEndInteractionEvt
to:
public void angleEndInteractionEvt(vtkObject sender, vtkObjectEventArgs e) {
//some stuff
EndInteractionEvt(sender, e);
}
Upvotes: 1