调用Windows窗体变得太慢了...... [英] Invoking Windows Forms become too slow...

查看:89
本文介绍了调用Windows窗体变得太慢了......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我使用Asterisk.NET Library从星号服务器接收事件..

但是,我不能直接在事件中更新表单,就像在另一个线程上一样。 (跨线程问题blaablaablaa)

我现在使用Invoke方法更新表单控件,,,但它看起来很慢(约5秒或更长时间)

如何我能快点吗?除了调用从另一个线程访问表单控件之外是否有任何想法。这是我的代码...



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.... :(

推荐答案

试试这个,它在我的应用程序中工作正常:

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>


从Asterisk.NET调用的New_State_Event是什么?



每次调用New_State_Event事件时,都会调用阻塞主UI线程的方法和New_State_Event来自的工作线程。



使用BeginInvoke并查看是否有帮助。
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.


这篇关于调用Windows窗体变得太慢了......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆