DragDrop registration did not succeed

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

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

What does this except

9条回答
  •  情歌与酒
    2021-02-07 08:29

    By far the easiest way is:

    private void DoSomethingOnGui()
    {
        if (this.InvokeRequired)
        {
            this.Invoke((MethodInvoker)delegate
            {
                Safe_DoSomethingOnGui();
            });
        }
        else
        {
            Safe_DoSomethingOnGui();
        }
    }
    private void Safe_DoSomethingOnGui()
    {
        // Do whatever you want with the GUI
    }
    

    You can even pass things along no problem:

    private void DoSomethingOnGui(object o)
    {
        if (this.InvokeRequired)
        {
            this.Invoke((MethodInvoker)delegate
            {
                Safe_DoSomethingOnGui(o);
            });
        }
        else
        {
            Safe_DoSomethingOnGui(o);
        }
    }
    private void Safe_DoSomethingOnGui(object o)
    {
        // Do whatever you want with the GUI and o
    }
    

提交回复
热议问题