Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
Queue<opcdatastructure.opcservertags> OPCitemQueue = new Queue<opcdatastructure.opcservertags>();

private void DataChangeHandler(object sender, DataChangeEventArgs e)
       {

           try
           {
           
               var thstoredatatable = new System.Threading.Thread(producer);
               thstoredatatable.Start(e);

           }
           catch { }
       }

 producer(object e)
{
  lock (myLockHolder)
                {
                    DataChangeEventArgs e113 = (DataChangeEventArgs)e;
                    int i ;                 
                    for (i=0; i < e113.sts.Length; i++)
                    {
                        opctag = new opcdatastructure.opcservertags();
                        opctag.value = Convert.ToString(e113.sts[i].DataValue);
                opctag.tagtimestamp = DateTime.FromFileTime(e113.sts[i].TimeStamp);
                        opctag.itemID = e113.sts[i].HandleClient;
                        opctag.quality = e113.sts[i].Quality;
                        int hour113 = e113.sts[i].TimeStampNet.Hour;
                        int minute113 = e113.sts[i].TimeStampNet.Minute;
                        int second113 = e113.sts[i].TimeStampNet.Second;
                        int millisecond113 = e113.sts[i].TimeStampNet.Millisecond;
                        int year113 = e113.sts[i].TimeStampNet.Year;
                        int month113 = e113.sts[i].TimeStampNet.Month;
                        int day113 = e113.sts[i].TimeStampNet.Day;
 DateTime sdate113 = new DateTime(year113, month113, day113, hour113, minute113,   second113, millisecond113);
    opctag.filetimestamp = sdate113.ToString("dd-MM-yyyy HH:mm:ss.fff");
                         lock (OPCitemQueue)
                        {
                            OPCitemQueue.Enqueue(opctag);
                            Monitor.Pulse(OPCitemQueue);
                        }
                         consumer consumer = new consumer(OPCitemQueue);
                         while (threaddatatable == null)
                         {
                     threaddatatable = new System.Threading.Thread(ThreadRun);
                             threaddatatable.Start();
                             threaddatatable.Join();
                         }
}
public void ThreadRun()//excutes 8 times
       {
           try
           {
              
               lock (OPCitemQueue)
               {
                   if (OPCitemQueue.Count == 0)
                   {
                       Monitor.Wait(OPCitemQueue);
                   }
                   opcdatastructure.opcservertags opctag = OPCitemQueue.Dequeue();
                       if (prameterupdate.X12 == 0)
                       {
                           prameterupdate.X12 = 1;
pu.update1(opctag.value, opctag.filetimestamp, opctag.tagtimestamp, opctag.quality, opctag.itemID);
                       }
                     
                     
               }         

              
           }
           catch { }
       }</opcdatastructure.opcservertags></opcdatastructure.opcservertags>


but after the 9th loop the ThreadRun() stop the execution but producer enqueue the items in the queue.why Threadrun()stop the execution?
Posted
Updated 1-Jun-11 1:56am
v3

1 solution

AT first glance: You have an empty catch block at the end of the thread procedure. If any exception at all happens, the thread procedure will terminate without any further sign of a problem. Sweeping exceptions under the rug never is a good idea, even when testing. If you catch them, then you must also handle them.
 
Share this answer
 
v2
Comments
vrushali katkade 1-Jun-11 8:21am    
OK i will be catch the exception but there is no exception catch
Sergey Alexandrovich Kryukov 1-Jun-11 16:15pm    
You do catch all exception in this procedure. Don't do it.
However, do catch all exception on top of stack of each thread.
Do not leave exceptions unattended, always log the exception or notify otherwise.
--SA
[no name] 1-Jun-11 8:28am    
How exactly do you know that? As it is you would not notice it in any way.
BobJanova 1-Jun-11 9:58am    
Agreed, except in very specific circumstances (and this is not one of them), you should always at the very least put the exception to console or a log file.

There is a lot more wrong with this code though.
vrushali katkade 2-Jun-11 0:12am    
then tell me which thing wrong with this code

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