using System; using System.Collections.Concurrent; using System.Threading; using System.Threading.Tasks; namespace Xylem.Common.CommonCore.ThreadWatcher { public sealed class TaskWatcher { #region Singleton private static readonly Lazy Lazy = new Lazy (() => new TaskWatcher()); public static TaskWatcher Instance => Lazy.Value; #endregion private TaskWatcher() { _tasks = new ConcurrentDictionary(); } private readonly ConcurrentDictionary _tasks; public void Add(Task t) { _tasks.TryAdd(Guid.NewGuid(), t); } } public sealed class ThreadWatcher { #region Singleton private static readonly Lazy Lazy = new Lazy (() => new ThreadWatcher()); public static ThreadWatcher Instance => Lazy.Value; #endregion private ThreadWatcher() { _threads = new ConcurrentDictionary(); } private readonly ConcurrentDictionary _threads; public void Start(Thread t) { t.Start(); _threads.TryAdd(Guid.NewGuid(), t); } } }