title: Webbrowser InvokeScript function is blocking UI thread in Windows Phone 8
body: <p>I am invoking a Javascript function using Webbrowser in Windows Phone 8. </p>
  
  <pre><code>browserControl.InvokeScript(funtionName, args);
  </code></pre>
  
  <p>This javascipt function is internally calling a service to fetch the data, during the javascript call i am showing ProgressIndicator.</p>
  
  <p>But i am not able to see ProgressIndicator because javascript call is stopping UI thread.</p>
  
  <p><strong>This problem may be because of Javascript function and my UI thread is running in same thread. So i tried to move my Javascript function call to Background thread, but it failed saying "Invalid cross thread Access"</strong></p>
  
  <p><strong>I am able to see the UI after my ScriptNotify is invoked. Before that i am not able to see my UI</strong></p>
  
  <p>You can see my code snippets below:</p>
  
  <p><strong>Can any one please suggest me how can i overcome this problem?</strong></p>
  
  <p>My progress indicator code:</p>
  
  <pre><code>public void ActivateProgressIndicator(this PhoneApplicationPage currentPage, string progressIndicatorText)
          {
              ProgressIndicator progressIndicator = new ProgressIndicator();
              progressIndicator.Text = progressIndicatorText;
              progressIndicator.IsVisible = true;
              progressIndicator.IsIndeterminate = true;
              SystemTray.SetProgressIndicator(currentPage, progressIndicator);
          }
  </code></pre>
  
  <p>My JS fucnction is calling a WCF rest service internally, this function call will take 30 seconds 1 minute. And i am JS code to Background thread like below:</p>
  
  <pre><code>ThreadPool.QueueUserWorkItem(o =&gt;
              {
                  WebBrowser browserControl = new WebBrowser();
                  browserControl.IsScriptEnabled = true;
                  browserControl.Navigate(new Uri("/WebAssets/Main.html", UriKind.RelativeOrAbsolute));
  
                  browserControl.InvokeScript("RetrieveAccounts",
                                                           "http://some.service.net/",
                                                           "Plain",
                                                           "arg1",
                                                           "arg2",
                                                           "arg3");
              });
  </code></pre>
  
  <p>I am getting Invalid cross thread error while i am creating the webbrowser control.</p>