private void BtnLoginUser_Click(object sender, RoutedEventArgs e) { // Start loading Gif LoadSpinner.Visibility = Visibility.Visible; // Disable login and make create button a cancel. BtnLoginUser.IsEnabled = false; BtnCreateUser.Content = "Cancel"; // Start the background worker. backgroundWorker.RunWorkerAsync(); } private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { // ?? Start the loading ?? //throw new NotImplementedException(); // backgroundWorker.ReportProgress((int)e.Argument); try { loginUser = SQLuserAccess.UserLogin(username, password); if (loginUser != null) { if (username == loginUser.Username && password == loginUser.Password) { } } } catch(Exception ex) { MessageBox.Show(ex.Message.ToString()); } } private void BackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { LblWatch.Content = "Processing " + e.UserState.ToString() + " : " + e.ProgressPercentage; //maybe here is where i run the loading.gif?? ?? free to interact with UI in progressChanged. LoadSpinner.Visibility = Visibility.Visible; } private void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { //Stop the loading RUNS when thread is COMPLETED can work on UI //throw new NotImplementedException(); BtnCreateUser.Content = "Register"; LoadSpinner.Visibility = Visibility.Hidden; if (loginUser.IsAdmin) { Window WindowAdminMenu = new AdminWindow(loginUser); WindowAdminMenu.Show(); Close(); } else if (loginUser.IsCustomer) { Window WindowCustomerMenu = new CustomerScreen(loginUser); WindowCustomerMenu.Show(); Close(); } else lblInvalidText.Content = "Invalid Account Information"; } private void LoadSpinner_MediaEnded(object sender, RoutedEventArgs e) { LoadSpinner.Position = new TimeSpan(0, 0, 1); LoadSpinner.Play(); }
Application.Current.Dispatcher.Invoke(delegate 17 { 18 backgroundWorker.ReportProgress(); //but what do i pass in and not sure if this is it 19 });
Invoke
ReportProgress
ProgressChanged
e.UserState
null
NullReferenceException
e.UserState.ToString()
LblWatch.Content = "Processing " + e.UserState + " : " + e.ProgressPercentage; // Or: LblWatch.Content = string.Format("Processing {0} : {1}", e.UserState, e.ProgressPercentage); // Or: LblWatch.Content = $"Processing {e.UserState} : {e.ProgressPercentage}";
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)