Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

BackgroundWorker and BindingSource Threading question

$
0
0

The documentation mentions the following:

You must be careful not to manipulate any user-interface objects in your DoWork event handler. Instead, communicate to the user interface through the ProgressChanged and RunWorkerCompleted events.

So if I have a datagridview, a typed dataset, a table adapter, and a binding source components on a form and the datagridview datasource is the binding source and the binding source data source is the typed dataset is it safe to fill the dataset with data in the DoWork event handler even though this will indirectly cause the UI to be updated (although presumable on the UI thread assuming the datagridview has subscribed to the ListChanged event of the bindingsource).  Here is a quick sample of what the code looks like:

public MyForm()
{
     InitializeComponent();
     backgroundWorker1.RunWorkerAsync();
}

privatevoid backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
     tableAdapter.Fill(myDataSet.myDataTable);
}

privatevoid backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
     if (e.Error != null) throw e.Error;
}

If this is not the best way to do this, what is the recommending approach?

Thanks!

Mike

 

 

 


Viewing all articles
Browse latest Browse all 2535

Trending Articles



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