Hi,
I am developing an application using Asterisk.NET Library, and I am subscribed to an event "NewStateEvent" to get the incoming calls from the server..
Now, I noticed that The NewState Event doesnt occur again until the last NewStateEvent is finished. I assume that its working on a single thread; that will start another thread only when the last one is finished... (I had to Invoke form to use form controls in the event)...
Is there any idea to allow mumltiple instances of a thread within my NewState Event ??
This is the code structure...
public void New_State_Event(object sender, Asterisk.NET.Manager.Event.NewStateEvent e)
{
if (e.ChannelStateDesc != null && e.Attributes.ContainsKey("connectedlinenum"))
{
switch (e.ChannelStateDesc.ToLower())
{
case "ringing":
if (ApplicationVariables.CurrentExtensions.ContainsValue(e.CallerIdNum))
{
this.Invoke(new MethodInvoker(delegate()
{
Label1.Text = "Ringing";
}));
}
break;
case "up":
if (CallingInfo.UniqueId == e.UniqueId)
{
this.Invoke(new MethodInvoker(delegate()
{
Label1.Text = "Line is up";
}));
}
break;
}
}
}
and Actual code is this ....
public void New_State_Event(object sender, Asterisk.NET.Manager.Event.NewStateEvent e)
{
try
{
if (e.ChannelStateDesc != null && e.Attributes.ContainsKey("connectedlinenum"))
{
switch (e.ChannelStateDesc.ToLower())
{
case "ringing":
if (ApplicationVariables.CurrentExtensions.ContainsValue(e.CallerIdNum))
{
try
{
this.Invoke(new MethodInvoker(delegate()
{
if (this.Opacity != 98) this.Opacity = 98;
if (exw != null && !exw.IsDisposed)
{
if (exw.calo != null && !exw.calo.IsDisposed)
exw.calo.Opacity = 0;
if (exw.cf != null && !exw.cf.IsDisposed)
exw.cf.Opacity = 0;
exw.Opacity = 0;
}
SetPopupLocation();
button8.Visible = true;
button1.Visible = true;
button2.Visible = true;
button4.Visible = false;
linkLabel1.Visible = false;
pictureBox1.Enabled = true;
if (!this.Visible)
{
this.Show();
this.TopMost = true;
}
if (exw != null && exw.Visible)
{
if (LOADSTYLE == NativeClasses.AW_VER_POSITIVE)
{
Taskbar tt = new Taskbar();
exw.Top = 121 + tt.Size.Height;
}
else
{
Rectangle rr = new Rectangle();
rr = Screen.GetWorkingArea(rr);
exw.Top = (rr.Height) - (exw.Height + 121);
}
}
label2.Text = String.Format(Language.incoming_call_for_the_extension, e.CallerIdNum);
if (e.Attributes.ContainsKey("connectedlinename") && e.Attributes.ContainsKey("connectedlinenum"))
{
CallingInfo.linenum = e.Attributes.ContainsKey("connectedlinenum") ? e.Attributes["connectedlinenum"] : " Unknown ";
label1.Text = String.Format(Language.num_is_calling, CallingInfo.linenum, CallingInfo.linenum, "", "");
Application.DoEvents();
if (e.Attributes["connectedlinename"] != "" && e.Attributes["connectedlinename"] != e.Attributes["connectedlinenum"])
{
CallingInfo.linename = e.Attributes["connectedlinename"];
}
else
{
Type officeType = Type.GetTypeFromProgID("Outlook.Application");
if (officeType == null || ApplicationVariables.look_for_contact_in_outlook == false)
{
if (ApplicationVariables.use_local_phone_book == true)
CallingInfo.linename = GetPhoneContact(e.Attributes["connectedlinenum"]);
else
CallingInfo.linename = "Unknown";
}
else
{
CallingInfo.linename = OutlookData.SearchContact(OutlookData.OutlookContactList, e.Attributes["connectedlinenum"]);
if (CallingInfo.linename == "Unknown")
CallingInfo.linename = GetPhoneContact(e.Attributes["connectedlinenum"]);
}
}
}
label1.Text = String.Format(Language.num_is_calling, CallingInfo.linename, CallingInfo.linenum,"","");
CallingInfo.channel = e.Channel;
CallingInfo.CalledExten = e.CallerIdNum;
CallingInfo.UniqueId = e.UniqueId;
CallingInfo.CallTaken = false;
Status_counter = 0;
timer_autohangup.Enabled = true;
CallerInfo.SetCallInfo(CallingInfo.linename, CallingInfo.linenum, e.CallerIdNum, 0, DateTime.Now, e.UniqueId);
SendStatustoXMPP("Phone Ringing...");
}));
}
catch (Exception ex)
{
DebugLogger.LogRecord(ex.Message + " [ Function: " + System.Reflection.MethodBase.GetCurrentMethod().Name + ", Thread, Class: ContactList ]");
}
}
break;
case "up":
if (CallingInfo.UniqueId == e.UniqueId)
{
this.Invoke(new MethodInvoker(delegate()
{
CallingInfo.CallTaken = true;
button8.Visible = false;
button1.Visible = true ;
button2.Visible = false;
button4.Visible = true;
linkLabel1.Visible = false;
pictureBox1.Enabled = false ;
timer_autohangup.Enabled = false;
label2.Text = String.Format(Language.talking, e.CallerIdNum);
label1.Text = string.Format(Language.talking_to, CallingInfo.linename , CallingInfo.linenum );
CallerInfo.SetCallInfo(CallingInfo.linename, CallingInfo.linenum, e.CallerIdNum, 1, DateTime.Now, e.UniqueId);
SendStatustoXMPP("Calling over Asterisk...");
}));
}
break;
}
}
}
catch (Exception ex)
{
DebugLogger.LogRecord(ex.Message + " [ Function: " + System.Reflection.MethodBase.GetCurrentMethod().Name + " Class: " + this.GetType().Name + " ]");
}
}
Please Help...