System.InvalidOperationException: DragDrop registration did not succeed. ---> System.Threading.ThreadStateException:
What does this except
Yes, I realize this question was asked 2 and a half years ago. I hit this exception and did some reading on it. I corrected it, but didn't see my solution anywhere, so I thought I'd post it somewhere someone else could read.
One possibility for this happening with [STAThread]
marked on the Main()
is if you're running this on a thread other than the one you started on.
I just ran into this exception when trying to create and show a new form in a BackgroundWorker.DoWork
method. To fix it, I wrapped the creation and showing of my new form into a method, and then called Invoke
on that method so that it fired on the UI thread. This worked because the UI thread started from the Main()
method with [STAThread]
marked, as other answers here explained.