DirectOutputR1
DirectOutput framework R1 for virtual pinball cabinets.
Go to:
Overview 
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros Pages
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;
5 using DirectOutput.General.Generic;
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 }