【发布时间】:2011-12-29 16:00:29
【问题描述】:
在线程方面我还是个新手,但是在使用以下代码时我得到了InvalidOperationException。我知道它正在尝试访问importFileGridView,但这是由创建异常的 UI 线程创建的。我的问题是,我该如何解决这个问题? GetAllImports 是否有可能具有返回类型?如何从我的 UI 线程访问 temp?
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);
}
【问题讨论】:
标签: c# .net multithreading threadpool