在UI-Thread问题中使用控件?

时间:2015-06-05 11:30:36

标签: c# voip

我的工作中有什么问题,我尝试使用UI线程。

private void btn_Call_Click(object sender, EventArgs e)
    {
        MakeCall();
    }

private void MakeCall()
    {
        try
        {
            //Get the IP we want to call.
            otherPartyIP = new IPEndPoint(IPAddress.Parse(txtCallToIP.Text), 1450);
            otherPartyEP = (EndPoint)otherPartyIP;

            //Get the vocoder to be used.
            if (cmbCodecs.SelectedText == "A-Law")
            {
                vocoder = Vocoder.ALaw;
            }
               else if (cmbCodecs.SelectedText == "u-Law")
            {
                vocoder = Vocoder.uLaw;
            }
            else if (cmbCodecs.SelectedText == "None")
            {
                vocoder = Vocoder.None;
            }

            //Send an invite message.
            SendMessage(Command.Invite, otherPartyEP);             
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "VoiceChat-Call ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }          
    }

返回错误:

  

跨线程操作无效:从a访问控制'btn_Call'   除了在

上创建的线程以外的线程

1 个答案:

答案 0 :(得分:0)

调用导致调度程序调用问题的行:

 Application.Current.Dispatcher.Invoke(...

从您发布的错误消息中,我们不清楚导致您的问题的作业。可能是其中之一:

otherPartyIP = new IPEndPoint(IPAddress.Parse(txtCallToIP.Text), 1450);
otherPartyEP = (EndPoint)otherPartyIP;
vocoder = Vocoder.ALaw;
vocoder = Vocoder.uLaw;
vocoder = Vocoder.None;