|
I have the following code that does NOT raise a cross thread exeption. Its a datagridview that uses a bindingsource and a dataset as a datasource of the bindingsource. So in my dowork of the backgroundworker, i manipulate the data, modify, delete, add ... I thought that it would generate a cross thread .. or a thread exception ... due to the fact that the bindingsource has the dataset as its datasource ... but it does not ... could someone explain to me why .... ??? here is a code example ..
public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'customerDataSet1.Customers' table. You can move, or remove it, as needed. this.customersTableAdapter.Fill(this.customerDataSet1.Customers);
}
private void button1_Click(object sender, EventArgs e) { using (BackgroundWorker worker = new BackgroundWorker()) { worker.DoWork += new DoWorkEventHandler(worker_DoWork); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted); worker.RunWorkerAsync(); } }
void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { bindingSource1.ResetBindings(false); }
void worker_DoWork(object sender, DoWorkEventArgs e) { foreach (CustomerDataSet.CustomersRow row in customerDataSet1.Customers) { row.ContactName = "a"; }
CustomerDataSet.CustomersRow newRow = customerDataSet1.Customers.NewCustomersRow(); newRow.CustomerID = "asdf"; newRow.CompanyName = "asdf";
customerDataSet1.Customers.AddCustomersRow(newRow); } }
|