Well the issue most coders have when multi-threading their application is that the threads often trip over each other - or often have timing issues - or will just flat out get exceptions when trying to alter a UI element in some way that requires the UI thread.
In your case what is going to happen is your form is going to display before your data is ready to be displayed - causing a blank datagrid and eventually an exception when your background thread attempts to put the data in the view. What you might try doing is to display a loading window of some kind until the data is ready to be displayed - and then show the data view.
Now - the exception you may have seen if you've tried this can be solved by calling the "Invoke" method off of any UI element. The invoke method will add whatever task you give it to the UI execution queue on the UI thread.
To see what I'm talking about - put together a form and give it a textbox. Then try this out:
var myworker = new BackgroundWorker();
myworker.DoWork += delegate
{
TextBox1.Text = "SampleText";
TextBox1.Refresh();
}
myworker.RunWorkerAsync();
you should have received an error saying something about cross threading ui something or other
This is how this is solved:
var myworker = new BackgroundWorker();
myworker.DoWork += delegate
{
TextBox1.Invoke(new MethodInvoker(delegate
{
TextBox1.Text = "SampleText";
}));
}
myworker.RunWorkerAsync();
This will place the assignment statement on the UI thread and will wait for it to execute before proceeding.
Now keep in mind you want to do all of your processing outside of the UI thread so only put what you absolutely have to in the Invoke method and nothing more.
For more information about multithreading look into "Thread Locking", "deadlock", "livelock", and "threadsafe". These keywords will help illustrate what issues you might run into in a multi threaded environment.
></\/~Psightoplasm`~