Please note ahead of time this is the first time working with multiple threads and my first attempt to use a second thread to populate/edit a DataSet then to display that DataSet into a Windows form that is dedicated to the DataGridView control. I've read various articles about thread safe code and I believe I'm going about it correctly.
During debugging, the DataSet is passed into the BackgroundWorker and pulled out of the thread with e.Result. Then it's assigned back to the variable that is used throughout the program.
When looking into the memory of the DataSet object, it has all the data that is loaded into it when it arrives to the frmGridView but the control is never updated.
Here are the pieces of my code. Any recommendations, suggestions, ideas for better code organization/structure would be most helpful. Again, this is my first at bat with BackgroundWorker.
Thanks!
Method Snippets:
private DataSet ProcessListXml(DataSet _dsData, BackgroundWorker _bwThread)
..
_dsData.Tables["MainList"].BeginLoadData();
..
DataRow row = _dsData.Tables["MainList"].NewRow();
..
_dsData.Tables["MainList"].Rows.Add(row);
..
_bwThread.ReportProgress((currLine / totalLines) * 100);
} //reader.Read()
..
_dsData.Tables["MainList"].EndLoadData();
_dsData.Tables["MainList"].AcceptChanges();
return _dsData;
DataGridView Windows Form:
public partial class frmDataView : Form
{
DataSet dsGameList;
public frmDataView(DataSet _in)
{
dsGameList = _in;
InitializeComponent();
dataGridView.DataSource = dsGameList.Tables["GameList"];
}
public void RefreshView()
{
dataGridView.Refresh();
}
BackgroundWorker Snippet:
private void bwThread_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
e.Result = ProcessMameListXml(dsData, worker);
}
private void bwThread_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
dvProgressBar.UpdateProgressBar(e.ProgressPercentage);
}
private void bwThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
dsData = (DataSet)e.Result;
dvProgressBar.Close();
UpdateUIElements();
dvWindow.RefreshView();
}