我得到“当前线程必须设置为单线程单元 (STA) 模式,然后才能进行 OLE 调用。确保您的 Main 函数上标记了 STAThreadAttribute。仅当调试器附加到进程时才会引发此异常”错误。这是以下代码。
if (externalButton.Checked == true)
{
// int i = 1;
saveFileDialog.Title = "Save the Proofer Report";
saveFileDialog.Filter = "Document Files (*.doc)|*.doc|Document Files (*.docx)|*.docx";
saveFileDialog.FilterIndex = 0;
saveFileDialog.InitialDirectory = "MyDocuments";
saveFileDialog.FileName = "Proofer Report -- " + Path.GetFileName((string)fileName) + ".doc";
//i.tostring()
saveFileDialog.DefaultExt = ".doc";
saveFileDialog.ShowHelp = true;
saveFileDialog.ShowDialog();-----getting the error here
fname = saveFileDialog.FileName;
}
else
{
fname =(string)fileName;
}
if (fname != "")
{
if (worker.CancellationPending == true)
{
// report progress
worker.ReportProgress(25);
return;
}
程序.cs
[STAthread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}