我试图在单击按钮时显示进度条,并在工作完成时将其隐藏。但是当我在按钮事件处理程序中显示进度条时,它不起作用,只有在工作完成后才会显示。
这是我的代码:
private void Button_Click_1(object sender, RoutedEventArgs e)
{
this.Dispatcher.BeginInvoke((Action)(() =>
{
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 && 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)(() =>
{
loadingprgoress.Visibility = Visibility.Hidden;
}));
return;
}
}