0

我正在使用for循环来拨打电话号码列表。我想从列表中取出第一个号码并拨打电话并等待响应,然后继续处理列表中的下一个号码。我曾经AutoResetEvent这样做过。但它不起作用。

for (int k = 0; k < list_Items.Count; k++) {
    Number_To_Call = "9" + list_Items[k].ToString();

    phoneCall.Start();

    waitingToPickUp.Set(); //AutoReset Event

    Thread.Sleep();

    waitingToPickUp.WaitOne();

    string detector = VoiceDetected;

    if (detector == "Machine") {
        //code
    } else if (detector == "Human") {
        //code
    } else {
        //code
    }
}

从呼叫中获取响应的代码

void phoneCall_CallStateChanged(object sender, VoIPEventArgs<CallState> e)
        {
            if (e.Item.IsInCall())
            {
                phoneCallAudioReceiver.AttachToCall(phoneCall);
                phoneCallAudioSender.AttachToCall(phoneCall);
                manchineDetector.Start();
                waitingToPickUp.Set();

                string str = VoiceDetected;

            }
            else if (e.Item.IsCallEnded())
            {
                phoneCallAudioReceiver.Detach();
                phoneCallAudioSender.Detach();
                manchineDetector.Stop();
                phoneCall = null;

                //Number_To_Call = string.Empty;

                InvokeOnGUIThread(() =>
                {
                    Number_To_Call = string.Empty;
                });
            }
        }

检测机器或人的代码

void manchineDetector_DetectionCompleted(object sender, VoIPEventArgs<AnswerMachineDetectionResult> e)
        {
            try
            {    
                string VoiceDetected = e.Item.ToString();    

            }
            catch (Exception ex)
            {
            }
        }
4

1 回答 1

0

Set并且立即WaitOne没有意义 - 等待不需要等待任何东西并立即继续。

最有可能应该是reset-call-wait:

  waitingToPickUp.Reset(); 
  phoneCall.Start();
  waitingToPickUp.WaitOne();
于 2013-03-26T02:01:27.730 回答