I am basically trying to run my authorization process for my WinRt app synchronously, but everything I've tried appears to deadlock the app after authorization on the MainPage, preventing navigation to the HomePage. Can't seem to figure it out. Here is my code without modifications, which works perfectly fine asynchronously below. How can I make this work synchronously:
Class:
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);
});
}
code that calls the method from 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));
}