FourSquare–part 3 of 4

Last time I authenticated the user within FourSquare use by running the browser.But it is not so good because you have no control over what the user does.

So the application must authenticate within ÔÇô and here comes the GUI with a WindowsForm( simple for me than WPF) and a WebBrowser control.

The code for the authentication is  simple. On the  <WebBrowser>_DocumentCompleted I verify that the url is the same with the URL that I use previously to retain the authentication for each user( )

private void wb4Sq_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            if (e.Url.ToString().StartsWith(this.finalUrl))
                this.DialogResult = DialogResult.OK;



On the main console thread I wait to the WebBrowser to finish on a separate thread:

 var th = new Thread(() =>

                var clicker = new WebBrowser { ScriptErrorsSuppressed = true };

                clicker.Visible = true;
                clicker.DocumentCompleted += clicker_DocumentCompleted;
                //while (clicker.ReadyState != WebBrowserReadyState.Complete)
                //    Application.DoEvents();
            int nrSecondsToWait = 5 * 60;
            while (!authenticated && nrSecondsToWait > 0)
                nrSecondsToWait -= 5;
                Console.WriteLine("waiting" + nrSecondsToWait);

            if (!authenticated)
                throw new ArgumentException("not connected to foursquare");

Practically is the same process as the previous, just the browser is within the application, not outside:

Next time I will make a short review of what I have done.
Source code at