Click here to Skip to main content
15,913,027 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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.
C#
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 { }
  }
}

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.
Posted
Updated 2-May-11 0:52am
v2
Comments
vrushali katkade 3-May-11 2:50am    
but data change handler invoke continously like timer if we delete the invoke required it will not excute continously

1 solution

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".

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


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.
 
Share this answer
 
Comments
vrushali katkade 3-May-11 5:46am    
can you please tell me the reason to don't used the InvokeRequired
Kim Togo 3-May-11 5:54am    
Yes, I can try.
When DataChangeHandler is called from OPCDA.Net component, it is already in a thread (from the ThreadPool), and you do not change ANY UI controls in DataChangeHandler method, therefor you do not have to check InvokeRequired. InvokeRequired is only used IF you have to change any UI controls. Etc. TextBox.Text = "My text".
vrushali katkade 4-May-11 2:31am    
thanks for reply
vrushali katkade 13-May-11 2:37am    
when i will be connected the network computer OPC server it will be connected when i will be start the datachange handler it will be display the exception Exception from HRESULT: 0x80040202(Advise Cannot Connect or Unable to open the access token of the current thread)
please tell me the solution
Kim Togo 13-May-11 3:19am    
I am sorry. But I have no knowledge about OPC server and how it works. I think you have read the manual for OPCDA.Net or contact those who have developed OPCDA.Net.

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