1

I'm learning to code, but there are things that i still don't know. As it is difficult to me explain what I want, here I show the code.

public class classOne {

    classTwo object = new ClassTwo();

    (...)

    public void WhenClassTwoHasEnded {
        (...)
    }
}

public class classTwo {

    public classTwo () {(...)}

    public classTwoAsyncStuff {
        (...)
        notifyEnd();
    }

    public void notifyEnd() {
        //How I can call WhenClassTwoHasEnded from here?
    }
}

Usually I always find the answer to my questions on Stack Overflow, but I've been searching for a while and have not found anything, because of my English.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Adelaiglesia
  • 365
  • 1
  • 4
  • 16

1 Answers1

1

It's possible to do that in many different ways. Here are some:

1) Let ClassOne run the method of its ClassTwo instead of calling it directly. So ClassOne has an (async if you want) method in which it calls await classTwo.classTwoAsyncStuff() and then this.WhenClassTwoHasEnded()

2) You could add event handlers

3) You could also send the Action or Func to the method and let it run it when it's done.

Community
  • 1
  • 1
Trafz
  • 636
  • 3
  • 13
  • That's what I was looking for! Thank you very much for your answer. I hope to continue learning and not have to ask much more. I am very grateful for your response. – Adelaiglesia Apr 04 '14 at 23:28
  • And you're welcome. But you shouldn't be afraid of asking for help if you're stuck and can't find the answer. It'll save you a lot of time and you might learn some new and interesting things :) – Trafz Apr 04 '14 at 23:31