Simply3DScan
Singleton.cs
Go to the documentation of this file.
1 using System;
2 
3 namespace SharedObjects
4 {
9  public static class Singleton<T> where T : class, new()
10  {
14  private static T instance;
18  private static readonly object lockObj = new object();
19 
26  public static T Instance
27  {
28  get
29  {
30  if (instance != null)
31  return instance;
32 
33  lock (lockObj)
34  {
35  if (instance == null)
36  {
37  try
38  {
39  instance = new T();
40  }
41  catch (Exception ex) // ex is for debugging only
42  {
43  instance = null;
44  }
45  }
46  return instance;
47  }
48  }
49  }
50  }
51 }
Class for creating a singleton for a generic class
Definition: Singleton.cs:9
static T Instance
Gets the instance.
Definition: Singleton.cs:27