DragDrop registration did not succeed

前端 未结 9 1821
时光取名叫无心
时光取名叫无心 2021-02-07 08:14

System.InvalidOperationException: DragDrop registration did not succeed. ---> System.Threading.ThreadStateException:

What does this except

9条回答
  •  太阳男子
    2021-02-07 08:44

    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.

提交回复
热议问题