views:

49

answers:

1

I have a method Modify which doing a operation ClientModify inside

 public bool Modify()
{
bool retval = false;

retval = Spa.ClientModify(col);

}

Here what i wanted is the ClientModify should perform only after three events completed in the eventhandler "ServerEvents" otherwise it should return retval as false .How can i do that checks before doing the operation "Spa.ClientModify"

static private void ServerEvents(eventType type, event this_event, object passback)
{

         if (this_event.type == eventType.SPD_spurtEvent)
        { 

           if (this_event.objectName == "ready")
            {                  
           // some operation 
            }
           else if (this_event.objectName == "info")
            {
           // some operation
            }

           else if (this_event.objectName == "serverstate")
            {
           // some operation
            }
        }

}

Some how i added a variable bool Yes= false in the eventhandler "ServerEvents" and once this check completed else if (this_event.objectName == "serverstate") i made it as yes=true,,But here the problem i am facing is i cant able to get yes boolean variable inside Modify() method ,i will get ServerEvents,but not able to instantiate.How can i do this or is there any other mechanism for that

+2  A: 

If you need to check if 3 methods have been completed, and they aren't currently leaving a trail of changed properties that allow you to check already, what you need to do is have them modify some properties when each of them executes, then you check each of those properties in your modify method to see if those events have executed.

public class MyState
{
    public bool Method1HasExecuted { get; set; }
    public bool Method2HasExecuted { get; set; }
    public bool Method3HasExecuted { get; set; }
}

public class MyClass
{
    public MyState MyClassState { get; set; }

    public void Method1() { MyClassState.Method1HasExecuted = true; }
    public void Method2() { MyClassState.Method2HasExecuted = true; }
    public void Method3() { MyClassState.Method3HasExecuted = true; }

    public bool Modify()
    {
        return MyClassState.Method1HasExecuted && MyClassState.Method2HasExecuted && MyClassState.Method3HasExecuted ? Spa.ClientModify() : false;
    }
}
Jimmy Hoffa
Can you explain it through code,,you mean get set property
peter
@peter: I think I can speak for everyone reading this when I say, I have no idea what you are talking about. If you have a friend who speaks better english than you, maybe have them ask the question.
Jimmy Hoffa
i am not able to do the instantiation public MyState MyClassState { get; set; } in the event handler static private void ServerEvents
peter