Friday, 15 April 2011

c# - RunWorkerCompleted is returning before work seems to be completed -


I am using a query to fill a blankbox in the WPF application. I have a pop, but all the items are immediately closed before loading in the box. There is no way to control this. I have a passive busy indicator inside the Runawalkar compartment method, but it appears that it has been done before. Here's what I have:

  private void before looking link (object sender, routing avent ARG e) {CboCustomerList.Items.Clear (); Busy indicator Isubcussi = true; BackgroundWorld SearchWorker = new backgroundwork (); ItemSearchWorker.DoWork + = New DoWorkEventHandler (FillCustomers); ItemSearchWorker.RunWorkerCompleted + = New RunWorker Component Action Handler (itemSearchWorker_Completed); ItemSearchWorker.RunWorkerAsync (); } Private void before SearchWorker_Completed (object sender, RunWorkerCompletedEventArgs e) {//busyIndicator.Visibility = System.Windows.Visibility.Hidden; Busy indicator ISUB = false; } Private Zero FillCustomers (Object Sender, DoWorkEventArgs E) {SqlDataAdapter Adapter = New SqlDataAdapter (); Dataset ds = new dataset (); String sql = "Siititibl to Choosing NAME of orders; String Connection String = settings. Difoltkprodkshn connection; 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 & lt; string & gt; ListOfString = new list & lt; string & gt; (); while (ReaderkRead ()) {ListOfStringkAdd (reader [ "NAME"]. ToString ());} Dispatcher.Invoke ((action) (() = & gt; CboCustomerList.ItemsSource = listOfString)) ; Connection.Close ();} < / Code> 

Note the settings of the indicator before calling, and to close the busy indicator in the item SearchWorker_Completed function, until the entire function is not asked before, should not wait? < According to MSDN, you should never manipulate the UI object in the background worker dwarf event.

You should be careful not to manipulate any user-interface objects in your Duplicate Event Handler. Instead, change the progress and contact the user interface via Runwalker's Comprehensive Event.

in your FillCustomers method that I recommend you to change this line:

  dispatcher. Invoke (Action) (() => CboCustomerList.ItemsSource = listOfString);  

To do this:

  e. Results = ListoffString;  

is now complete:

  Private Void Item SearchWorker_Completed (Object Sender, RunWorkerCompletedEventArgs e) {CboCustomerList.ItemsSource = e.Result list form In & lt; String & gt ;; //busyIndicator.Visibility = System.Windows.Visibility.Hidden; Busy indicator ISUB = false; }  

No comments:

Post a Comment