I have a ThreadStateException in my WinForms application.
Step to reproduce:
- Create simple winforms app
- Add a Timer
In click event, do :
timer1.Interval = 1000; timer1.Tick += timer1_Tick; timer1.Start();
with
void timer1_Tick(object sender, EventArgs e) { ThreadPool.QueueUserWorkItem(delegate { StringCollection paths = new StringCollection { @"c:\my.txt", @"c:\my.png" }; Clipboard.SetFileDropList(paths); }); }
The exception tells me:
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.
But the main has already the [STAThread] attribute.
How to solve it?