Hi,

I am trying to write some code in which one class, when it reaches a certain state, tells its parent class to do something:

Code:
class classA
{
    classB B;
    public classA()
    {
        B = new classB();
    }
    public functionA(){}
}

class classB
{
    int x;
    public functionB()
    {
        // Modifies the value of x in a random way
    }
}

class Main
{
    A = new classA();
    A.B.functionB() /* This is called lots and lots, until x happens to  equal 50. When x = 50, I want to dispose of B, and call A.functionA().*/
}
I don't want to have to keep asking if (A.B.x == 50) after every call to functionB, because x is only equal to 50 after, on average, hundreds of calls to functionB(), so this would be very inefficient. Function B changes x randomly so there is no way of telling when exactly x will equal 50.

So, how can I tell A to do something once B reaches a certain state....could I use some sort of event handler, such that x=50 raises and event, thus telling A do dispose of B and so on?

I am very new to C# and would like to know what the code for such an event handler would be, or any other suggestions on how I might implement this.

Thank you!