program debugging under. Net is a lot simpler and less of a problem than the headaches of the pointer crossing the line. However, when your program encounters the following problems, it is still very tricky:
1. The process terminates abnormally. Solutions see unhandled exceptions under. Net
2. The program has not been released after a memory leak or memory request. solutions see Using. NET Memory Profiler to track. NET application memory usage-Basic application. If the program is monitored by myself, I will explain it in a later article.
3. Threads are suspended for unknown reasons, such as deadlocks.
4. Program dead Loop.
This article will explain if the program to write the two fault real-time tracking and reporting.
First, we need a separate monitoring thread to monitor the threads that need to be monitored.
I made a monitor class Threadmonitor, before we started monitoring, we set the monitoring thread to the highest priority.
public ThreadMonitor()
{
_MonitorThread = new Thread(new ThreadStart(MonitorTask));
_MonitorThread.Priority = ThreadPriority.Highest;
_MonitorThread.IsBackground = true;
}
Next we provide several common methods for this thread
The Start method allows the caller to initiate the monitoring
The Register method is used to register the threads that need to be monitored into the monitoring list
The Heartbeat method is followed by a description
/**////<summary>
///Start monitor
///</summary>
Public void Start ()
{
_monitorthread.start ();
/**////<summary>
///Monitor Register
///</summary>
<param name= "Monitorpara" >monitor parameter</param>
public void Register (Monitorparameter Monitorpara)
{
Debug.Assert (Monitorpara!= null);
Debug.Assert (monitorpara.thread!= null);
if (GETTCB (monitorpara.thread)!= null)
{
throw new System.argu Mentexception ("Register repeatedly!");
}
Lock (_registerlock)
{
_tcbtable.add (monitorpa Ra. Thread.managedthreadid, New TCB (Monitorpara));
}
}
public void Heartbeat (Thread t)
{
TCB TCB = GETTCB (t);
if (TCB = null)
{
throw new System.ArgumentException ("This thread WA s not registered! ");
}
TCB. Lastheartbeat = DateTime.Now;
TCB. Hittimes = 0;
TCB. Status &= ~threadstatus.hang;
}