Hi,
Just to append Sahil's sample,
In DataBinding we may use async delegation to retrieve data, however we
could not change the DataSet in that thread, since the databinding
mechanism will fire the events on the bounded controls and let them
updates, however if the change is made on another thread, the updates code
will also be run on that threas which will cause "freeze" problem, Windows
Form or Control methods cannot be called on a thread other than the one
that created the form or control.
Here is a modified version of the sample:
<code>
public class MyForm : Form
{
public delegate void AdoNETDelegate() ;
public delegate void UpdateDelegate(DataSet deltaDS);
public void RetrieveAndProcessData()
{
//Not in the UI thread.
//create a temporary dataset /datatable etc to process the data
//so that we will not mess the databinding events.
DataSet deltaDS = new DataSet();
// Your Processing Logic
//Executes a delegate asynchronously on the thread that
//the control's underlying handle was created on.
this.BeginInvoke(new UpdateDelegate(OnWorkDone),new object[]{deltaDS});
}
public void Button1_Clicked(object sender, EventArgs e)
{
MethodInvoker delly = new MethodInvoker(this.RetrieveAndProcessData);
delly.BeginInvoke(null,null);
}
private void OnWorkDone(DataSet deltaDS)
{
//OK, we are in the right thread context.
//do Merge or some other operations on the bounded dataset
}
}
</code>
Does it resolve your problem?
If you have anything unclear please feel free to post it in this thread.
Have a nice day!
Best regards,
Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.