C# 异步方法?
我需要在Monotouch中异步调用webservice,因为UIAlertView只在工作完成后显示 当前代码(伪代码) 我正在将服务方法移动到异步模型中,身份验证由C# 异步方法?,c#,multithreading,xamarin.ios,C#,Multithreading,Xamarin.ios,我需要在Monotouch中异步调用webservice,因为UIAlertView只在工作完成后显示 当前代码(伪代码) 我正在将服务方法移动到异步模型中,身份验证由BeginAuthenticate()、EndAuthenticate()、authenticatesync()、OnAuthenticateOperationCompleted()组成,当然还有Authenticate() 当所有这些都完成后,我需要在LoginViewController上运行AuthenticateCompl
BeginAuthenticate()、EndAuthenticate()、authenticatesync()、OnAuthenticateOperationCompleted()
组成,当然还有Authenticate()
当所有这些都完成后,我需要在LoginViewController上运行AuthenticateCompleted(),因此我将使用BeginInvokeOnMainThread(委托…
这就是我被卡住的地方
如何从服务类执行LoginViewController类实例中的AuthenticationCompleted()方法
编辑:解决方案:
添加了连接到Login()中的OnAuthenticateCompleted事件处理程序,并调用AuthenticateTasync()方法而不是Authenticate()
您不从服务类执行
LoginViewController。在AuthenticationCompleted
上,您在已完成的事件处理程序中执行它
class LoginViewController
{
void Login (credentials)
{
service.AuthenticateAsync (credentials, LoginCompletedCallback);
}
}
void LoginCompletedCallback ()
{
BeginInvokeOnMainThread (OnAuthenticateCompleteded);
}
}
Class LoginviewController
{
void Login(credentials)
{
showAlert("Logging in") ;
service.AuthenticateCompleted += new GetAuthenticationCompletedEventHandler(OnAuthenticateCompleted);
service.AuthenticateAsync(Credentials);
}
public void OnAuthenticateCompleted(obj sender, GetAuthenticationCompletedEventArgs args)
{
bool authenticated = (bool)args.Results;
//do stuff
hideAlert();
}
}
class LoginViewController
{
void Login (credentials)
{
service.AuthenticateAsync (credentials, LoginCompletedCallback);
}
}
void LoginCompletedCallback ()
{
BeginInvokeOnMainThread (OnAuthenticateCompleteded);
}
}