run the progress bar in another thread
<p>I am trying to show a progress bar when I click a button, and hide it when the work is finished. But when I show the progress bar in the button event handler, it doesn't work and  is only shown after the work is done.</p>

<p>Here is my code:</p>

<pre><code>private void Button_Click_1(object sender, RoutedEventArgs e)
{
    this.Dispatcher.BeginInvoke((Action)(() =&gt;
        {
            loadingprgoress.Visibility = Visibility.Visible;
        }));

    int usresult, psresult;

    con.Open();

    SqlDataReader data = null;
    String myQueryEdit1 = @"SELECT Username, Password FROM [dbo].[Table]";
    com.CommandText = myQueryEdit1;
    com.Connection = con;
    data = com.ExecuteReader();
    Random rnd = new Random();
    int newrnd = rnd.Next(1, 100);

    if (data.Read())
    {

        string userhash = GenerateHashWithSalt(data["Username"].ToString(), newrnd.ToString());
        string passhash = GenerateHashWithSalt(data["Password"].ToString(), newrnd.ToString());
        string userhash1 = GenerateHashWithSalt("admin", newrnd.ToString());
        string passhash1 = GenerateHashWithSalt(pasbox.Password, newrnd.ToString());

        usresult = userhash.CompareTo(userhash1);
        psresult = passhash.ToString().CompareTo(passhash1);
        if (usresult == 0 &amp;&amp; psresult == 0)
        {
            con.Close();
            dental_main_Window neww = new dental_main_Window();
            neww.Show();
            Close();
        }
        else
        {
            con.Close();
            pasbox.Password = "";
        }

        Thread.Sleep(3000);

        this.Dispatcher.BeginInvoke((Action)(() =&gt;
           {
               loadingprgoress.Visibility = Visibility.Hidden;
           }));
        return;
    }
}
</code></pre>
