0

I am currently using SOAP Web Service in my iOS app using Xamarin C#. I want to have a nested callback to continue execution on Main UI Thread. Here's the example:

[WebService Method]
WSMethod(param A){
     //do something
}

class A
{
    InnerFunction(param A)
    {
         ws.BeginWSMethod(A, new AsyncCallback(WSMethodCallback), WebService);
    }

    WSMethodCallBack(IASyncResult ar)
    {
         //first callback here
         result = ws.EndWSMethod(ar);
    }
}

class B
{
    OuterFunction()
    {
         //define param A..
         InnerFunction(A);

         //nested callback function - to be executed when WSMethodCallback finish
         UpdateUIMethod();
    }
}

How do I call 'UpdateUIMethod()' once the WSMethodCallBack has finished executing?

UPDATE:

UpdateUIMethod is an instance method of Class A that should be called within the corresponding instance (not a static method)

yonasstephen
  • 2,645
  • 4
  • 23
  • 48

1 Answers1

1

The simplest approach would be to simply call UpdateUIMethod inside WSMethodCallBack after you have called ws.EndWSMethod. You would need to marshal the call to UpdateUIMethod back to the UI.

I'm not massively familiar with Xamarin but I'd expect you could also look to use some of the newer framework features that make async development simpler although it's hard to know if that is appropriate in your case.

As of .Net 4.0 you can use TaskFactory.FromAsync to simplify the calling of asynchronous methods that follow the BeginXXX/EndXXX pattern.

Daniel Kelley
  • 7,579
  • 6
  • 42
  • 50