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 { get { return lazy.Value; } } #endregion private TaskWatcher() { tasks = new ConcurrentDictionary(); } private 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 { get { return lazy.Value; } } #endregion private ThreadWatcher() { threads = new ConcurrentDictionary(); tasks = new ConcurrentDictionary(); } private ConcurrentDictionary threads; private ConcurrentDictionary tasks; public void Start(Thread t) { t.Start(); threads.TryAdd(Guid.NewGuid(), t); } } }