Пример #1
0
        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;
                }
            }
        }
Пример #2
0
        public static void RenameCurrent(string name)
        {
            BindedThread bt = GetCurrent();

            if (bt != null)
            {
                bt.Name = name;
            }
        }
Пример #3
0
        /// <summary>
        /// Устанавливает идентификатор запроса для текущего потока
        /// </summary>
        /// <param name="id"></param>
        public static void SetQueryId(Guid id)
        {
            BindedThread bt = GetCurrent();

            if (bt != null)
            {
                bt.QueryId = id;
            }
        }
Пример #4
0
        public static int GetDebugId()
        {
            BindedThread bt = GetCurrent();

            if (bt != null)
            {
                return(bt.DebugId);
            }
            return(-1);
        }
Пример #5
0
        private static BindedThread GetCurrent()
        {
            BindedThread bt = null;

            lock (Threads)
            {
                Threads.TryGetValue(Thread.CurrentThread.ManagedThreadId, out bt);
            }
            return(bt);
        }
Пример #6
0
 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);
             }
         }
     }
 }