Forum Xamarin.iOS

How to handle async tasks

Programmer16Programmer16 USMember ✭✭

Hello,

I've been trying to debug this asynchronous call I'm working with with an external service, Pubnub (https://www.pubnub.com/docs/c-sharp-dotnet-c-sharp/api-reference#here_now_example_4) and I'm trying to tackle it from two angles. I seem to be running into a question that might be Xamarin-related, so I am going to post it here.

I'm running the code as mentioned in the link in my question, and in my Xamarin debug window, I am seeing

Thread started: <Thread Pool> #9
Thread started: <Thread Pool> #10
Thread started: <Thread Pool> #11
Thread finished: <Thread Pool> #10
Thread finished: <Thread Pool> #11
Thread finished: <Thread Pool> #9

My code never seems to execute, and I don't know if I need to handle asynchronous functions differently in Xamarin, or if it's even possible. The application seems to hang when I stick the code in a TouchUpInside event in my ViewController

button.TouchUpInside += delegate {
    pubnub.HereNow()
        .IncludeState(true) // include state with request (false by default)
        .IncludeUUIDs(true) // if false, only shows occupancy count
        .Async(new DemoHereNowResult());
}

//....

public class DemoHereNowResult : PNCallback<PNHereNowResult> {
    public override void OnResponse(PNHereNowResult result, PNStatus status) {
        Console.WriteLine("a");
    }
};

Does anyone have ideas?

Tagged:

Best Answer

Answers

Sign In or Register to comment.