"?" /> "? - 网页学习体会" />

如何修复“无法从方法组转换为"Func"?

如何修复“无法从方法组转换为"?" src="/default/index/img?u=aHR0cHM6Ly9wMi5waXFzZWxzLmNvbS9wcmV2aWV3LzM4OS8zNzQvMzM0L2F4LWhhdGNoZXQtYmxvY2std29vZC5qcGc=&w=245&h=&w=700"/>

问题描述:

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);
    }

Task.Factory.FromAsync 的第一个参数发生编译错误.我已经阅读了几个关于类似问题的线程,似乎没有一个帮助他们都提到这个具有不同的签名.请指出我正确的方向.

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.

使用签名编辑

开始登录签名

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

有一个很长的重载列表,但它似乎与您的不匹配

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

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

作为

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

所以我建议为 Targ1 指定 Type 参数,

So I would suggest specifying the Type argument for Targ1,

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

还要验证 lgParameters 的类型是否正确.

also verify that lgParameters is of the correct type.