每250毫秒调用一次数据更改处理程序 [英] data change handler invoking at every 250 miliseconds

查看:108
本文介绍了每250毫秒调用一次数据更改处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用OPCDA.Net组件的应用程序.我使用opcserver,用128个数据更改处理程序(128个并发线程)注册128个组.该应用程序不返回错误,它在前10分钟内可以正常工作,但随后停止.当我暂停应用程序以检查它在哪里停止时,我将每250毫秒调用一次此方法,这将不允许设置中断.

I have an application that uses the OPCDA.Net component. I use the opcserver, registering 128 groups with 128 data change handlers ( 128 simultaneous threads ). The application doesn''t return an error, it works fine the first 10 minutes, but then stops. i will be invoke this method at every 250 miliseconds when i will be pause the application to check where it will be stop it will not allow to set the break.

private void DataChangeHandler(object sender, DataChangeEventArgs e) 
{ 
// The invoke handling is only required when the callback handler writes data into Windows dialogs 
  try 
  { 
    if (InvokeRequired) 
    { 
       BeginInvoke(new DataChangeEventHandler(DataChangeHandler), new object[] { sender, e }); return; 
    } 
    if (parameter.X == 0) 
    { parameter.X = 1; Thread th = new Thread(param.update); th.Start(e); } 
    } 
    catch { }
  }
}


像这样,我将创建128个datachange处理程序方法.有时,当我执行此代码时,它将停止工作.您是否知道任何情况可能会使应用程序从BeginInvoke调用这些属性?当我仅运行2个datachnagehandler时,它将运行良好;当我尝试10个数据更改处理程序时,它将挂起;当我使用调试器进行测试时,它将删除工作指针,没有异常捕获.


like this i will be created the 128 datachange handler method. Sometimes, when I execute this code, it will be stop working. Do you know any circumstance that may hand the application calling these properties from a BeginInvoke? when i will be run th eonly 2 datachnagehandler it will be worked fine ,when i will try for 10 data change handler it will be hang,when i will be tested using the debugger it will remove the working pointer,there is no exception catch.

推荐答案

您好,Sangita

我不知道什么是OPCDA.Net.但是,当调用DataChangeHandler方法时,它是从ThreadPoll调用的,并且已经在另一个线程中,然后在您的UI线程中.因此,无需调用并检查InvokeRequired.您无需在DataChangeHandler方法中更改任何UI控件.

只需在"param.update"下调用该方法即可.

Hi Sangita

I do not know what OPCDA.Net is or done. But, when the DataChangeHandler method is called, it is called from the ThreadPoll and is already in another thread then your UI thread. So no need to call and check InvokeRequired. You do not change any UI controls in DataChangeHandler method.

Just call the method under "param.update".

try
{
  if (parameter.X == 0)
  {
    parameter.X = 1;
    param.update(e);
  }
  catch { }
}



并且,如果关于128线程正在运行,这是真的,那么我认为问题是您必须分配更多可在 ^ ].创建和销毁线程是一件昂贵的事情.



And if it is true about the 128 thread running, i think the problem is that you must allocate more thread that you can use in the ThreadPool.SetMinThreads[^]. Creating and destroying thread is a costly affair.


这篇关于每250毫秒调用一次数据更改处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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