Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 异步方法?_C#_Multithreading_Xamarin.ios - Fatal编程技术网

C# 异步方法?

C# 异步方法?,c#,multithreading,xamarin.ios,C#,Multithreading,Xamarin.ios,我需要在Monotouch中异步调用webservice,因为UIAlertView只在工作完成后显示 当前代码(伪代码) 我正在将服务方法移动到异步模型中,身份验证由BeginAuthenticate()、EndAuthenticate()、authenticatesync()、OnAuthenticateOperationCompleted()组成,当然还有Authenticate() 当所有这些都完成后,我需要在LoginViewController上运行AuthenticateCompl

我需要在Monotouch中异步调用webservice,因为UIAlertView只在工作完成后显示

当前代码(伪代码)

我正在将服务方法移动到异步模型中,身份验证由
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);
    }
}