Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

New Post: RunWorkerCompleted is returning before work seems to be completed. Busy indicator Closing Early

$
0
0
I am using a query to fill a combobox in a WPF application. I have the Xceed busy indicator that pops up, but then closes right away before all of the items are loaded into the box. is there some way to control this. I have the disable busy indicator inside a RunWorkerCompleted method, but it seems it calls this before its done.
Here's what I have:
            private void ItemSearch_Click(object sender, RoutedEventArgs e)
        {
            CboCustomerList.Items.Clear();
            directEntry.Height = 0;
            directEntry.Width = 0;
            Entry.IsChecked = false;
            busyIndicator.Visibility = System.Windows.Visibility.Visible;
            busyIndicator.IsBusy = true;
            Customer.Height = 32;
            Customer.Width = 814;
            ItemSearch.IsChecked = true;
            BackgroundWorker itemSearchWorker = new BackgroundWorker();
            itemSearchWorker.DoWork += new DoWorkEventHandler(FillCustomers);
            itemSearchWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(itemSearchWorker_Completed);
            
            itemSearchWorker.RunWorkerAsync();

        }

        private void itemSearchWorker_Completed(object sender, RunWorkerCompletedEventArgs e)
        {
            //busyIndicator.Visibility = System.Windows.Visibility.Hidden;
            busyIndicator.IsBusy = false;
        }
        
        private void FillCustomers(object sender, DoWorkEventArgs e)
        {
            

            SqlDataAdapter adapter = new SqlDataAdapter();
            DataSet ds = new DataSet();
            string sql = "Select * from CustTable order by NAME asc";
            string connectionString = Settings.Default.ProdConnectionString;
            SqlConnection connection = new SqlConnection(connectionString);
            SqlCommand SqlCmd = new SqlCommand();
            SqlCmd.CommandType = CommandType.Text;
            SqlCmd.Connection = connection;
            SqlCmd.CommandText = sql;
            SqlDataReader reader = null;
            connection.Open();
            reader = SqlCmd.ExecuteReader();
            List<String> listOfString = new List<string>();
            while (reader.Read())
            {
               listOfString.Add(reader["NAME"].ToString());
            }
            Dispatcher.Invoke((Action)(() =>CboCustomerList.ItemsSource = listOfString));

            connection.Close();


        }
Note the setting of the indicator before the call, and the turning off of the busy indicator in the itemSearchWorker_Completed function.
Shouldn't this wait until the whole function is called first?

Viewing all articles
Browse latest Browse all 4964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>