WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
ThreadInfo.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading;
6 
7 namespace DirectOutput.General
8 {
12  public class ThreadInfo : IDisposable
13  {
14  #region IDisposable Member
15 
19  public void Dispose()
20  {
21  Dispose(true);
22  GC.SuppressFinalize(this);
23  }
24 
25 
30  protected virtual void Dispose(bool disposing)
31  {
32  if (disposing)
33  {
34  // free managed resources
35 
36  }
37  // free native resources if there are any.
38  Thread = null;
39  }
40 
41  #endregion
42 
43 
44 
45 
46  private Queue<Exception> _Exceptions = new Queue<Exception>();
53  public IList<Exception> Exceptions
54  {
55  get { return _Exceptions.ToList(); }
56  }
57 
62  public void RecordException(Exception Exception)
63  {
64  _Exceptions.Enqueue(Exception);
65  if (_Exceptions.Count > 30)
66  {
67  _Exceptions.Dequeue();
68  }
69  }
70 
71 
78  public string HostName { get; set; }
79 
86  public Thread Thread { get; set; }
87 
94  public DateTime LastHeartBeat { get; private set; }
95 
99  public void HeartBeat()
100  {
101  LastHeartBeat = DateTime.Now;
102  }
103 
104  private int _HeartBeatTimeOutMs=1000;
105 
112  public int HeartBeatTimeOutMs
113  {
114  get { return _HeartBeatTimeOutMs; }
115  set { _HeartBeatTimeOutMs = value; }
116  }
117 
118 
119 
120 
121 
122 
129  public string ThreadName
130  {
131  get { return Thread.Name; }
132  }
133 
140  public bool IsAlive
141  {
142  get
143  {
144 
145  return Thread.IsAlive;
146  }
147  }
148 
153  public ThreadInfo(Thread Thread)
154  {
155  this.Thread = Thread;
156 
157 
158  HeartBeat();
159 
160  }
161 
165  public ThreadInfo()
166  : this(Thread.CurrentThread)
167  {
168 
169  }
170 
171 
175  ~ThreadInfo()
176  {
177  Dispose(false);
178  }
179 
180 
181  }
182 }
void HeartBeat()
HeartBeat has to be called regularely to update the LastHeartBeat property.
Definition: ThreadInfo.cs:99
ThreadInfo(Thread Thread)
Initializes a new instance of the ThreadInfo class.
Definition: ThreadInfo.cs:153
void RecordException(Exception Exception)
Adds a captured exception to the Expeptions list.
Definition: ThreadInfo.cs:62
This object provides information on a thread.
Definition: ThreadInfo.cs:12
ThreadInfo()
Initializes a new instance of the ThreadInfo class for the thread creating the instance.
Definition: ThreadInfo.cs:165
virtual void Dispose(bool disposing)
Releases unmanaged and - optionally - managed resources.
Definition: ThreadInfo.cs:30
void Dispose()
Cleans up the resources used by instances of this class.
Definition: ThreadInfo.cs:19