0

I dont understand this programming syntax around Dispatcher.RunAsync.

All I know is that I have to translate the following authentification module from Linq2Twitter working on WP8 to WP8.1.

async void Page_Loaded(object sender, RoutedEventArgs e)
{
    pinAuth = new PinAuthorizer
    {
        // Get the ConsumerKey and ConsumerSecret for your app and load them here.
        CredentialStore = new InMemoryCredentialStore
        {
            ConsumerKey = "",
            ConsumerSecret = ""
        },
        // Note: GetPin isn't used here because we've broken the authorization
        // process into two parts: begin and complete
        GoToTwitterAuthorization = pageLink => Dispatcher.BeginInvoke(
            () => OAuthWebBrowser.Navigate(new Uri(pageLink, UriKind.Absolute)))
    };

    await pinAuth.BeginAuthorizeAsync();
}

The problem is Dispatcher.BeginInvoke

I found the solution for the problem in here but I don't get it working with my programming skills.

I would also appreciate a link/video tutorial to this topic. I don't even know where to start learning about Dispatcher, Threading etc.

Cheers,

Chris

//Update

The following seems to work but I dont know how to retrieve the PIN value from this WebAuthenticationBroker

            pinAuth = new PinAuthorizer
        {
            // Get the ConsumerKey and ConsumerSecret for your app and load them here.
            CredentialStore = new InMemoryCredentialStore
            {
                ConsumerKey = "",
                ConsumerSecret = ""
            },
            // Note: GetPin isn't used here because we've broken the authorization
            // process into two parts: begin and complete
            GoToTwitterAuthorization = async pageLink => 
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, 
               () => { WebAuthenticationBroker.AuthenticateAndContinue(
                    new Uri(pageLink, UriKind.Absolute)); })
        };

        await pinAuth.BeginAuthorizeAsync();
Community
  • 1
  • 1
Ulpin
  • 179
  • 1
  • 14
  • Dispatcher.BeginInvoke is not available in WinRT based WP8.1 Apps. You can get a Dispatcher using CoreWindow.GetForCurrentThread().Dispatcher as described here: http://stackoverflow.com/questions/10579027/run-code-on-ui-thread-in-winrt – Oliver Ulm Apr 05 '16 at 16:51
  • Thank You. Sounds similiar to the solution I've linked in the question and therefore I'm still not able to do the transfer from this line of code: GoToTwitterAuthorization = pageLink => Dispatcher.BeginInvoke( () => OAuthWebBrowser.Navigate(new Uri(pageLink, UriKind.Absolute))) to the WinRT format... – Ulpin Apr 05 '16 at 17:14
  • 1
    I'd say if you get the dispatcher as described in those links from CoreWindow the line should translate to: GoToTwitterAuthorization = pageLink => await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { OAuthWebBrowser.Navigate(new Uri(pageLink, UriKind.Absolute)); }); – Oliver Ulm Apr 05 '16 at 17:23
  • updated my question @OliverUlm Thank You – Ulpin Apr 05 '16 at 22:19

0 Answers0