對於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
後完成的。如果我等待此任務並將結果設置爲某個變量,則可以使用異步方法訪問它並返回它。
但我無法弄清楚如何實現這一點。