private static void AddThread(Thread thr, string name, object owner, int debugId, int tid) { if (thr.Name == null) { thr.Name = name; } if (lastClean < DateTime.Now.AddMinutes(-5)) { ClearThreads(); } BindedThread bth = new BindedThread(thr, name, owner, debugId, tid); lock (Threads) { if (!Threads.ContainsKey(thr.ManagedThreadId)) { Threads.Add(thr.ManagedThreadId, bth); } else { Threads[thr.ManagedThreadId] = bth; } } }
public static void RenameCurrent(string name) { BindedThread bt = GetCurrent(); if (bt != null) { bt.Name = name; } }
/// <summary> /// Устанавливает идентификатор запроса для текущего потока /// </summary> /// <param name="id"></param> public static void SetQueryId(Guid id) { BindedThread bt = GetCurrent(); if (bt != null) { bt.QueryId = id; } }
public static int GetDebugId() { BindedThread bt = GetCurrent(); if (bt != null) { return(bt.DebugId); } return(-1); }
private static BindedThread GetCurrent() { BindedThread bt = null; lock (Threads) { Threads.TryGetValue(Thread.CurrentThread.ManagedThreadId, out bt); } return(bt); }
private static void ClearThreads() { lastClean = DateTime.Now; lock (Threads) { List <int> keys = new List <int>(Threads.Keys); foreach (int k in keys) { BindedThread bt = Threads[k]; if (bt.Thread == null || bt.Thread.ThreadState == System.Threading.ThreadState.Stopped) { Threads.Remove(k); } } } }