Home > Net >  Thread to stop
Thread to stop

Time:09-27

Thread with a while loop, found running thread automatically stop after a few hours, also can not capture anomalies, what reason

CodePudding user response:

1, really is without exception to stop, that is the loop condition does not meet the
2, there is abnormal, you have a problem of exception handling or processing;

CodePudding user response:

Jump out of the while loop, want to catch exceptions will be thrown exception to the thread of execution, the executing thread, automatic stop running a few hours is not accurate, not sure what have done in the process of running operations, to a certain condition is completed,

CodePudding user response:

How do you catch exceptions?

CodePudding user response:

Put your code

CodePudding user response:

reference 4 floor Summer_djz response:
your code to the

Try
{
While (true)
{
File. AppendAllText (@ "C: \ log. TXT", "running" + DateTime. Now + "\ t \ r \ n");
Thread.sleep (30);
UInt16 values=0;
Robot. ReadTrue (Convert. ToUInt16 (201), the ref values, 0).
//if (robot ReadWR (Convert ToUInt16 (201), the ref values, Convert the ToByte (0))==false)
//{
//File. AppendAllText (@ "C: \ log. TXT", "manipulator tasks unfinished" + DateTime. Now + "\ t \ r \ n");
//the continue;
//}
If (robot. ReadState ())
{
File. AppendAllText (@ "C: \ log. TXT", "monitoring to idle machines" + DateTime. Now + "\ t \ r \ n");
If (this. InserTask ()==false)
{
File. AppendAllText (@ "C: \ log. TXT", "began to switch the machine" + DateTime. Now + "\ t \ r \ n");
This fun ();
}
}
If (rack. ReturnTablePos (Global. PartToDoing)==false)
{
Bool cnc_1=CNC. ReturnCnc (" CNC - Ele - 27 ");
Bool cnc_2=CNC. ReturnCnc (" CNC - Ele - 28 ");
Bool cnc_3=CNC. ReturnCnc (" CNC - Ele - 29 ");
If (cnc_1==false & amp; & Cnc_2==false & amp; & Cnc_3==false)
{
BtnStart. Text="reboot";
break;
}
}
}

}
The catch (Exception e)
{
File. AppendAllText (@ "C: \ log. TXT", e. oString () + DateTime. Now + "\ t \ r \ n");
MessageBox. Show (e. oString ());
}
The finally
{
File. AppendAllText (@ "C: \ log. TXT", "is not found abnormal" + DateTime. Now + "\ t \ r \ n");
}
  •  Tags:  
  • C#
  • Related