WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
ThreadInfoList.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Threading;
6 
7 namespace DirectOutput.General
8 {
13  public class ThreadInfoList:List<ThreadInfo>
14  {
15 
16  private object ListUpdateLocker=new object();
17 
25  public void HeartBeat(object HostObject=null)
26  {
27  try
28  {
29  this[Thread.CurrentThread].HeartBeat();
30  }
31  catch (ArgumentException AE)
32  {
33  if (AE.ParamName == "Thread")
34  {
35  ThreadInfo TI = new ThreadInfo(Thread.CurrentThread);
36  if (HostObject != null)
37  {
38  if (HostObject is INamedItem)
39  {
40  TI.HostName = ((INamedItem)HostObject).Name;
41  }
42  else
43  {
44  TI.HostName = HostObject.GetType().Name;
45  }
46  }
47  lock (ListUpdateLocker)
48  {
49  this.Add(TI);
50  }
51  }
52  }
53  }
54 
62  public void HeartBeat(string HostObjectName)
63  {
64  try
65  {
66  this[Thread.CurrentThread].HeartBeat();
67  }
68  catch (ArgumentException AE)
69  {
70  if (AE.ParamName == "Thread")
71  {
72  ThreadInfo TI = new ThreadInfo(Thread.CurrentThread);
73  if(!HostObjectName.IsNullOrWhiteSpace()) {
74  TI.HostName = HostObjectName;
75 
76  }
77  lock (ListUpdateLocker)
78  {
79  this.Add(TI);
80  }
81  }
82  }
83  }
84 
90  public void RecordException(Exception Exception, object HostObject=null) {
91  HeartBeat(HostObject);
92  this[Thread.CurrentThread].RecordException(Exception);
93  }
94 
101  public void ThreadTerminates()
102  {
103  if (this.Contains(Thread.CurrentThread))
104  {
105  lock (ListUpdateLocker)
106  {
107  this.Remove(this[Thread.CurrentThread]);
108  }
109  }
110 
111  }
112 
113 
120  public ThreadInfo this[Thread Thread]
121  {
122  get
123  {
124  if (Contains(Thread))
125  {
126  return this.First(TI => TI.Thread == Thread);
127  }
128  throw new ArgumentException("The ThreadInfoList does not contain a ThreadInfo object for thread {0}.".Build(Thread.Name), "Thread");
129  }
130  }
131 
132 
140  public bool Contains(Thread Thread)
141  {
142  return this.Any(TI=>TI.Thread==Thread);
143  }
144 
145  }
146 }
This object provides information on a thread.
Definition: ThreadInfo.cs:12
Interface for items which can be added the the NamedItemList.
Definition: INamedItem.cs:8
List of ThreadInfo objects. This class is used by DOF for thread monitoring
void RecordException(Exception Exception, object HostObject=null)
This method records a exception which has been captured.
void ThreadTerminates()
Has to be called by the thread before it terminates. This command removes the thread from the List...
string HostName
Gets or sets the name of the object hosting the thread.
Definition: ThreadInfo.cs:78
void HeartBeat(object HostObject=null)
Calls the HeartBeat method of the ThreadInfo object for the specified thread. If the specified threa...
The namespace DirectOutput.General contains classes for general use.
bool Contains(Thread Thread)
Determines whether the list contains a ThreadInfo object for the given thread.
void HeartBeat(string HostObjectName)
Calls the HeartBeat method of the ThreadInfo object for the specified thread. If the specified threa...