void br_Navigating(object sender, WebBrowserNavigatingEventArgs e)
        {
            if (e.Url.AbsoluteUri.StartsWith(endLink))
            {
                // parse result
                string urlEnd = e.Url.ToString().Split('#')[1];
                Dictionary<string, string> values = new Dictionary<string, string>();
                string[] nameValues = urlEnd.Split(new[] { "&" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var nameValue in nameValues)
                {
                    // Separate this values by '=' so you get name/key and value as separated field in array
                    string[] temp = nameValue.Split(new[] { "=" }, StringSplitOptions.RemoveEmptyEntries);

                    if (temp.Length == 2)
                    {
                        values.Add(temp[0], WebUtility.UrlDecode(temp[1]));
                    }
                }

                Token = new TokenResult();
                Token.AccessToken = values["access_token"];
                Token.InstanceUrl = values["instance_url"];
                Token.RefreshToken = values["refresh_token"];

                // close window
                this.Close();
            }
        }
        void br_Navigating(object sender, WebBrowserNavigatingEventArgs e)
        {
            if (e.Url.AbsoluteUri.StartsWith(endLink))
            {
                // parse result
                string urlEnd = e.Url.ToString().Split('#')[1];
                Dictionary <string, string> values = new Dictionary <string, string>();
                string[] nameValues = urlEnd.Split(new[] { "&" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var nameValue in nameValues)
                {
                    // Separate this values by '=' so you get name/key and value as separated field in array
                    string[] temp = nameValue.Split(new[] { "=" }, StringSplitOptions.RemoveEmptyEntries);

                    if (temp.Length == 2)
                    {
                        values.Add(temp[0], WebUtility.UrlDecode(temp[1]));
                    }
                }

                Token              = new TokenResult();
                Token.AccessToken  = values["access_token"];
                Token.InstanceUrl  = values["instance_url"];
                Token.RefreshToken = values["refresh_token"];

                // close window
                this.Close();
            }
        }
        public TokenResult GetToken()
        {
            WebForm web = new WebForm(new Uri(ServiceRequestUri), CallbackUrl);
            // start in new thread
            var t = new Thread(delegate() { token = web.Start(); });
            t.SetApartmentState(ApartmentState.STA);
            t.Start();
            t.Join();
            //while (t.IsAlive)
            //{
            //    Thread.Sleep(5000);
            //}

            return token;
        }
        public TokenResult GetToken()
        {
            WebForm web = new WebForm(new Uri(ServiceRequestUri), CallbackUrl);
            // start in new thread
            var t = new Thread(delegate() { token = web.Start(); });

            t.SetApartmentState(ApartmentState.STA);
            t.Start();
            t.Join();
            //while (t.IsAlive)
            //{
            //    Thread.Sleep(5000);
            //}

            return(token);
        }