I am quite new when it comes to threading but I am getting an InvalidOperationException
when using the following code. I understand that it is trying to access importFileGridView
but this was created by the UI thread which creates the exception. My question is, how do I resolve this? Is it possible for GetAllImports to have a return type? How do I access temp
from my UI thread?
ThreadPool.QueueUserWorkItem(new WaitCallback(GetAllImports), null);
private void GetAllImports(object x)
{
DataSet temp = EngineBllUtility.GetAllImportFiles(connectionString);
if (temp != null)
importFileGridView.DataSource = temp.Tables[0];
else
MessageBox.Show("There were no results. Please try a different search", "Unsuccessful", MessageBoxButtons.OK, MessageBoxIcon.Information);
}