对于windows phone 8.1 microsoft引入了一些方法,以AndContinue
结尾。这些方法暂停应用程序以执行和处理用户输入。之后,他们调用一个Continue...
-方法,其中包含操作结果的对象。andcontinue() - 作为异步操作执行的方法
一个示例是WebAuthenticationBroker.AuthenticateAndContinue
,用于OAuth。
示例代码:
class Test : IWebAuthenticationContinuable
{
private void StartAuth()
{
WebAuthenticationBroker.AuthenticateAndContinue(new Uri("http://example.org/token?someInformations"),
new Uri("http://example.org/callback"), null, WebAuthenticationOptions.None);
}
private void ContinueWebAuthentication(WebAuthenticationBrokerContinuationEventArgs args)
{
WebAuthenticationResult result = args.WebAuthenticationResult;
//Do something with the result
}
}
在windows店应用相同的是通过使用WebAuthenticationBroker.AuthenticateAsync
-emthod achived。这个方法是一个简单的异步操作。
我想写一个AuthenticateAsync
-方法为windows手机使用AuthenticateAndContinue
。它必须返回一个Task<WebAuthenticationResult>
。
作为一个相当古怪的方法,我想到了一个Task
,这是在执行ContinueWebAuthentication
后完成的。如果我等待此任务并将结果设置为某个变量,则可以使用异步方法访问它并返回它。
但我无法弄清楚如何实现这一点。