DirectOutputR1
DirectOutput framework R1 for virtual pinball cabinets.
Go to:
Overview 
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros Pages
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  SetProcessorNumber();
103  }
104 
105  private int _HeartBeatTimeOutMs=1000;
106 
113  public int HeartBeatTimeOutMs
114  {
115  get { return _HeartBeatTimeOutMs; }
116  set { _HeartBeatTimeOutMs = value; }
117  }
118 
119 
127  public int ProcessorNumber
128  {
129  get;
130  private set;
131  }
132 
133  private bool GetCurrentProcessorNumberIsAvailable = false;
134  private void SetProcessorNumber()
135  {
136  if (GetCurrentProcessorNumberIsAvailable)
137  {
138  ProcessorNumber = Kernel32Imports.GetCurrentProcessorNumber();
139  }
140  }
141 
142 
143 
150  public string ThreadName
151  {
152  get { return Thread.Name; }
153  }
154 
161  public bool IsAlive
162  {
163  get
164  {
165 
166  return Thread.IsAlive;
167  }
168  }
169 
174  public ThreadInfo(Thread Thread)
175  {
176  this.Thread = Thread;
177  GetCurrentProcessorNumberIsAvailable = Kernel32Imports.GetCurrentProcessorNumberIsAvailable;
178 
179  HeartBeat();
180 
181  }
182 
186  public ThreadInfo()
187  : this(Thread.CurrentThread)
188  {
189 
190  }
191 
192 
196  ~ThreadInfo()
197  {
198  Dispose(false);
199  }
200 
201 
202  }
203 }