Click here to Skip to main content
12,255,451 members (51,435 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# threads
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...

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 15-Oct-13 23:38pm
Edited 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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Try this, it works fine in my application:
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>
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160426.1 | Last Updated 16 Oct 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100