我被这个问题困惑了很长时间。我使用 System.Threading 启动新线程,就像这样:
ParameterizedThreadStart threadFileExport = FileExport;
Thread threadExport = new Thread(threadFileExport)
{
IsBackground = true,
Name = "threadExport",
Priority = ThreadPriority.AboveNormal
};
threadExport.Start(_dataTable);
和
public void FileExport(object objTable)
{
SaveFileDialog saveFileDialog = new SaveFileDialog
{
DefaultExt = "xlsx",
Filter = "Excel 2007-2010|*.xlsx|" +
"Excel95,97,2003|*.xls|",
FileName = "table.xlsx",
Title = "Save as. . ."
};
saveFileDialog.ShowDialog();
}
但是对话框不会显示,并且执行“ShowDialog”时线程似乎会立即中止。这是一个错误还是我犯了一个错误?后台线程可以显示保存文件对话框吗?