winform app, i have a grid view and the datasource populate (on bind function) by delegate begin invoke sapareted thread, but the gridView DataSource cannot get the generated value from the new thread because the gridview was created on Main Thread:
Here i invoke new thread
private void button_selectFile_Click(object sender, EventArgs e)
{
if (resultLoadingFile == DialogResult.OK)
{
filename = openFileDialog_logLoader.FileName;
string name = System.IO.Path.GetFileName(filename);
label_selectFileStatus.Text = name;
readDelegate parseAndSplit = new readDelegate(ReadLogFileAndDrawTable);
AsyncCallback cb = new AsyncCallback(doneReadFile);
IAsyncResult ar = parseAndSplit.BeginInvoke(filename, cb, dataGridView_mainTable);
}
}
Here i call bind:
private void doneReadFile(IAsyncResult ar)
{
Bind();
}
And this is Bind():
private void Bind(){
TableLoadMgr.ItemsLoaded = TableModelListFiltered.Count();
updateLoadedStatus();
//The following line throw exception:
dataGridView_mainTable.DataSource = TableModelListFiltered;
}
The exacly question is:
How do i fire Bind() on the Main Thread since the callback function fire on the new delegate thread.
Remarks:
- Duplicate subject question i saw didn't answer winform and the constraints
- Timer is not an option
- new user trigger (such button "show" after thread complete) is no an option