private void Recorder_ExecuteCode(object sender, EventArgs e)
{
fileName = "";
SendMail = false;
CallIsAlive = true;
Recorder recorder = new Recorder();
// Use the call ID as the filename and create a media sink.
Random rnd = new Random();
fileName = string.Format("C:\\recordings\\Inbound Call\\EmergencyCall {0}.wma", DateTime.Now.Day.ToString() + "." + DateTime.Now.Month.ToString() + "." + DateTime.Now.Year.ToString() + " - " + DateTime.Now.Hour.ToString() + "." + DateTime.Now.Minute.ToString() + "." + DateTime.Now.Second.ToString() + rnd.Next().ToString());
WmaFileSink fileSink = new WmaFileSink(fileName);
Console.WriteLine("Recording for 10 seconds.");
// Set the recorder to use the media sink and attach
// it to the flow.
recorder.SetSink(fileSink);
recorder.AttachFlow(Program.MyCall.Flow);
// Start recording.
recorder.Start();
SendMail = true;
}
上面的代码设置了一个附加到入站呼叫的audiovideoflow的记录器。
我遇到的问题是,如果同时进入2个调用并尝试调用Recorder_executeCode函数,程序将崩溃:
recorder.AttachFlow(Program.MyCall.Flow);
Visual Studio报告以下错误:
用户代码未处理InvalidOperationException。 AudioVideoFlow已绑定到记录器。
如果两个或多个呼叫者同时呼叫,我将如何更改代码以允许同时运行多个功能副本。
修改
问题是由使用全局变量引起的:MyCall
我通过使用Call.CallId
设置文件名字符串来解决问题 private void Recorder_ExecuteCode(object sender, EventArgs e)
{
string fileName;
SendMail = false;
Recorder recorder = new Recorder();
// Use the call ID as the filename and create a media sink.
//Random rnd = new Random();
fileName = string.Format("C:\\recordings\\Inbound Call\\EmergencyCall {0}.wma", acceptCallActivityInboundCall1.CallProvider.ToneController.AudioVideoFlow.Call.CallId.ToString());
WmaFileSink fileSink = new WmaFileSink(fileName);
Console.WriteLine("Recording for 10 seconds.");
// Set the recorder to use the media sink and attach
// it to the flow.
recorder.SetSink(fileSink);
recorder.AttachFlow(acceptCallActivityInboundCall1.CallProvider.ToneController.AudioVideoFlow);
// Start recording.
recorder.Start();
SendMail = true;
}