views:

94

answers:

3

This is a C# question I want to do a synchronous call for asynchronous event call backs. See comment in code for the req

class User
{
    EventHandler Service1Started()
    {
      "Looks like service 1 started as I got event from server class" ;
    }
    EventHandler Service2Started()
    {
      "Looks like service 2 started as I got event from server class" ;
    }
    public void StartServicesOnlyStartService2AfterService1Started()
    {
        Server server = new Server();

         // want to call these 2 methods synchronously here
        // how to wait till service1 has started thru the event we get
        // Want to avoid polling, sleeping etc if possible

        server.StartService1();              
        server.StartService2();

    }
}
+3  A: 

Your code is pretty unclear, but the simplest approach would just be to make the event handler for Service1 start service 2:

server.Service1Started += delegate { server.StartService2(); };
Jon Skeet
I changed question.The need is to synchronously call two methodswithout using polling etc
john appleseed
@john appleseed: Your question was fairly unclear before - it's even less clear now. What *exactly* do you mean by "synchronously" in this case? You need to make your question a lot clearer. Your methods `Service1Started` and `Service2Started` have odd signatures for event handlers, and just have string literals in... basically it's all a mess. The more clearly you can express your question, the better the chance that we can actually help you.
Jon Skeet
Sorry. I think I need to come up with better explanation of what I need. Also looking around Rx ( Reactive extensions ) looks like a good candidate for solution but looks very complex. Thanx so far.
john appleseed
@john: If you can come up with a clearer description, I'll be happy to take a look. Rx is certainly both complex and awesome :)
Jon Skeet
+2  A: 

Jon's answer is right, this is the equivalent in case it's not convenient to use delegate:

EventHandler Service1Started()
{
    // Looks like service 1 started as I got event from server class
    server.StartService2();
}
egrunin
A: 

Will come back if needed after going thru Rx.

john appleseed