gpt4 book ai didi

c# - pjsip c#, System.AccessViolationException 在一个单独的线程上接听来电

转载 作者:行者123 更新时间:2023-11-30 23:10:19 27 4
gpt4 key购买 nike

overrided void onIncomingCall 中,我打开了一个新的后台线程,它显示了一个 new (Popup) Form。我尝试接听或拒绝此表单中的调用,但随后收到 System.AccessViolationException。似乎当前的调用对象被锁定,无法从另一个窗体访问。如果我在 onIncomingCall void 中使用 currentcall.answer(prm),则调用已成功建立(没有其他表单和线程)。

public class myaccount : Account
{

public override void onIncomingCall(OnIncomingCallParam prm)
{
Call call = new Call(this, prm.callId);
CallOpParam param = new CallOpParam();


param.statusCode = pjsip_status_code.PJSIP_SC_RINGING;
param.statusCode = pjsip_status_code.PJSIP_SC_OK;
pjsipfunctions.currentparam = param;
pjsipfunctions.currentcall = call;


var thread = new Thread(() =>
{
ShowPopup(call,prm.callId.ToString());

});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();

// Thread myCallingThread = new Thread(new ThreadStart(ShowPopup));
//myCallingThread.SetApartmentState(ApartmentState.STA);
//myCallingThread.IsBackground = true;
//myCallingThread.Start();



}
public void ShowPopup(Call myCall,string call_id)
{
IncommingCallPopup win = new IncommingCallPopup(ref myCall, call_id );

win.Show();
System.Windows.Threading.Dispatcher.Run();


}


}

#####################################
public IncommingCallPopup(ref Call info, string callid)
{
currentCall = info;
Callid = callid;
CurrentCall = currentCall;
Prm.statusCode = pjsip_status_code.PJSIP_SC_RINGING;
InitializeComponent();
labelCallId.Content = callid;

}

private void rejectcall(object sender, RoutedEventArgs e)
{
Prm.statusCode = pjsip_status_code.PJSIP_SC_DECLINE;
CurrentCall.hangup(Prm);
}

private void transfercall(object sender, RoutedEventArgs e)
{

}

private void takecall(object sender, RoutedEventArgs e)
{

Prm.statusCode = pjsip_status_code.PJSIP_SC_OK;
try
{
CurrentCall.answer(Prm);
}
catch(Exception ex)
{

}

}

最佳答案

经过疯狂的搜索和尝试,我已经弄明白了。每个线程都必须在端点中注册,您可以在另一个类(窗口)中挂断、接听或转移调用。

您只需在公共(public)类中编写此方法,并在每次从另一个窗口调用您的 void 时调用此 void ->

public void callpopup(String number) {
checkThread();

//answer, decline or something else

}

[MethodImpl(MethodImplOptions.Synchronized)]
public static void checkThread()
{
try
{

if (ep != null && !ep.libIsThreadRegistered())
ep.libRegisterThread(Thread.CurrentThread.Name);

}
catch (Exception e)
{


}
}

关于c# - pjsip c#, System.AccessViolationException 在一个单独的线程上接听来电,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45408488/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com