getting error - System.InvalidOperationException was unhandled

前端 未结 1 1755
离开以前
离开以前 2021-01-22 07:08

I have just started to learn windows application development, and we have been given self learn project to develop one windows application. I am trying to create the application

1条回答
  •  悲哀的现实
    2021-01-22 07:12

    You can access Form GUI controls in GUI thread and you are trying to access outside GUI thread that is the reason for getting exception. You can use MethodInvoker to access controls in the GUI thread.

    void sendMethod()
    {
        MethodInvoker mi = delegate{
           string lblText = (String) MsgSender.sendSMS(to, msg, "hotmail", uname, pwd);
           pictureBox1.Visible = false;
           lblMsgStatus.Visible = true;
           lblMsgStatus.Text = 
                 lblText + "\nFrom: " + uname + 
                 " To: " + cmbxNumber.SelectedItem + " " + count;
       }; 
    
       if(InvokeRequired)
           this.Invoke(mi);
    }
    

    0 讨论(0)
提交回复
热议问题