Click here to Skip to main content
15,880,967 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi friends,

I am using Asterisk.NET Library to recieve events from an asterisk server..
But, I cant update the forms directly in events as its on another thread. (Cross-threading problem blaablaablaa)
I am now using Invoke methode to update the form controls,,, But it seems very slow (About 5 seconds or more)
How can I make it fast ? Is there any idea other than Invoking to access form controls from another thread. Here is my code...

C#
public void New_State_Event(object sender, Asterisk.NET.Manager.Event.NewStateEvent e)
{
        this.Invoke(new MethodInvoker(delegate()
        {
              Label1.Text = e.Channel + " Calling" ;
        }));
}


Please Help me.... :(
Posted
Updated 16-Oct-13 0:53am
v2
Comments
lukeer 16-Oct-13 7:10am    
The GUI thread my be busy and therefore not able to respond faster. I had that once caused by a TextBox that was frequently updated.

Try this, it works fine in my application:
C#
public void New_State_Event(object sender, Asterisk.NET.Manager.Event.NewStateEvent e)
{
     UpdateLabel( e.Channel + " Calling" );
        
}

private void UpdateLabel(string textForLabel)
{
  if (this.Label1.InvokeRequired)
  {
     this.Invoke (new Action<string>(UpdateLabel), new object[] {textForLabel});
     return;
  }
  else
     Label1.Text= textForLabel;
}
</string>
 
Share this answer
 
At what rate is "New_State_Event" called from Asterisk.NET ?

Every time "New_State_Event" event is called, you invoke a method that is blocking the Main UI Thread and the worker thread where "New_State_Event" is coming from.

Use "BeginInvoke" and see if that helps.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900