John D
John D

Reputation: 639

proper way to return monotouch asynchronous calls

Lets say i have an asynchoronous call in my monotouch project like this

context.getNameCompleted += HandleContextgetNameCompleted;
context.getNameAsync();

void HandleContextgetNameCompleted(object sender, getNameCompletedEventArgs args)
    {
        string name = args.Result;
    }

Now how do I get another asynchronous method running that relies on the completion of the first without getting the program to crash. So for instance my second call might be

context.getAgeCompleted += HandleContextgetAgeCompleted;
context.getAgeAsync();

void HandlegetAgeCompleted(object sender, getAgeCompletedEventArgs args)
    {
        string age = args.Result;
    }

the second method can only return a value once we return the "name" from the first person. Please provide in reasons and/or examples of how to properly use this method or any alternate solution.As usual your help is much appreciated

Upvotes: 1

Views: 252

Answers (1)

Jason
Jason

Reputation: 89102

Fire the 2nd request when you handle the completion of the first one.

void HandleContextgetNameCompleted(object sender, getNameCompletedEventArgs args)
    {
        string name = args.Result;

        context.getAgeCompleted += HandleContextgetAgeCompleted;
        context.getAgeAsync();

    }

Upvotes: 2

Related Questions