【发布时间】:2010-06-07 14:19:19
【问题描述】:
我的 WinForms 应用程序中有一个 ThreadStateException。
重现步骤:
- 创建简单的 winforms 应用程序
- 添加计时器
-
在点击事件中,做:
timer1.Interval = 1000; timer1.Tick += timer1_Tick; timer1.Start();与
void timer1_Tick(object sender, EventArgs e) { ThreadPool.QueueUserWorkItem(delegate { StringCollection paths = new StringCollection { @"c:\my.txt", @"c:\my.png" }; Clipboard.SetFileDropList(paths); }); }
异常告诉我:
在进行 OLE 调用之前,必须将当前线程设置为单线程单元 (STA) 模式。确保您的 Main 函数上标记了 STAThreadAttribute。
但是main已经有了[STAThread]属性。
如何解决?
【问题讨论】:
标签: c# winforms multithreading clipboard