我基本上是在尝试同步地为我的 WinRt 应用程序运行我的授权过程,但是我尝试过的所有操作似乎都会在 MainPage 上授权后使应用程序死锁,从而阻止导航到 HomePage。似乎无法弄清楚。这是我没有修改的代码,它在下面异步工作得很好。我怎样才能使这项工作同步:
班级:
public async void InitializeTwitterAsnc()
{
WinRtAuthorizer authorizer = null;
authorizer = new WinRtAuthorizer()
{
Credentials = new LocalDataCredentials()
{
ConsumerKey = "blah379",
ConsumerSecret = "blah123"
},
UseCompression = true,
Callback = new Uri("http://blah.com")
};
if(!authorizer.IsAuthorized)
{
await authorizer.AuthorizeAsync();
}
// set the twitter credential fields
await Task.Run
(() =>
{
twitterName = authorizer.Credentials.ScreenName;
twitterId = authorizer.Credentials.UserId;
accessToken = authorizer.Credentials.AccessToken;
oAuthToken = authorizer.Credentials.OAuthToken;
this.TwitterContext = new TwitterContext(authorizer);
});
}
从 MainPage.xaml.cs 调用方法的代码:
private void StartTwitterLogin(object sender, RoutedEventArgs e)
{
// start the twitter authorization
TwitterAuth twitAuth = new TwitterAuth();
twitAuth.InitializeTwitterAsnc();
this.Frame.Navigate(typeof (HomePage));
}