【发布时间】:2013-11-25 09:53:29
【问题描述】:
我的应用程序中有两种形式,一种是在设计时生成的,另一种是在运行时动态生成的。在运行时生成的表单中有一个上下文菜单,其中有一个打开FolderBrowserDialog 的项目。每当我尝试单击该项目时,就会出现错误提示
Current thread must be set to single thread apartment (STA) mode before OLE
calls can be made. Ensure that your Main function has STAThreadAttribute
marked on it. This exception is only raised if a debugger is attached to the
process.
如在其他问题中所解释的,上述问题的解决方案是将Main() 方法标记为[STA Thread],但在我的情况下已经存在。那么,我该如何解决这个问题呢?
我调用对话框的方式是:-
private void RightClickMenuClicked(object sender, ToolStripItemClickedEventArgs e)
{
if (e.ClickedItem.ToString() == "Copy")
{
FolderBrowsing.ShowDialog() ;
// Do other stuff here ....
}
}
【问题讨论】:
-
你能贴一些代码说明你是怎么做到的吗?
-
@Szymon 我已经发布了一些代码。
标签: c# .net multithreading user-interface sta