3
try
    {
      var login = ToServiceLogin(lgParameters);
      await Task.Factory.FromAsync(loginOperation.BeginLogin,
loginOperation.EndLogin, lgParameters, TaskCreationOptions.None);

    }
    catch (FaultException fe)
    {
        Debug.WriteLine(@"          {0}", fe.Message);
    }
    catch (Exception ex)
    {
        Debug.WriteLine(@"              ERROR {0}", ex.Message);
    }

Compile error occurs on the first parameter of Task.Factory.FromAsync. I've read up on a couple of threads regarding similar issue none seems to be helping they all refer to this having a different signature. Please point me to the right direction.

EDIT With Signature

BeginLogin Signature

IAsyncResult BeginLogin(PRPClockingXamarin.PRPServiceMobile.LoginParameters loginParams,
                         AsyncCallback callback, object asyncState);
H H
  • 263,252
  • 30
  • 330
  • 514
Lord-David
  • 535
  • 1
  • 11
  • 34

2 Answers2

3

There is a long terse list of overloads but it seems it won't match your

IAsyncResult BeginLogin(
    LoginParameters loginParams,
    AsyncCallback callback, 
    object asyncState);

as the argument for

  Func<TArg1, AsyncCallback, object, IAsyncResult> beginMethod,

So I would suggest specifying the Type argument for Targ1,

FromAsync<PRPClockingXamarin.PRPServiceMobile.LoginParameters> (...)

also verify that lgParameters is of the correct type.

H H
  • 263,252
  • 30
  • 330
  • 514
  • This worked I no longer have the error, thank you. The issue now is that it says my LoginResponse has the wrong return type. Any Idea where I could be going wrong? – Lord-David Jan 09 '17 at 11:23
  • I don't see any LoginResponse – H H Jan 09 '17 at 11:30
  • LoginResponse is part of the EndLogin signature PRPClockingXamarin.PRPServiceMobile.LoginResponse EndLogin(System.IAsyncResult result); – Lord-David Jan 09 '17 at 11:35
  • 1
    I think you need yet another overload, [`FromAsync(Func, Func, TArg1, Object, TaskCreationOptions)`](https://msdn.microsoft.com/en-us/library/dd321447(v=vs.110).aspx) . – H H Jan 09 '17 at 11:59
0

When using FromAsync, I usually recommend setting up the parameters as: begin method, end method, begin method arguments (except callback/state), and null. The final null is for the state:

await Task.Factory.FromAsync(loginOperation.BeginLogin, loginOperation.EndLogin,
    lgParameters, null);
Stephen Cleary
  • 437,863
  • 77
  • 675
  • 810