Beispiel #1
0
 /// <summary>
 /// 初始化后台帮助线程
 /// </summary>
 /// <param name="backthreadSize">后台帮助线程的数量</param>
 static public void Init(int backthreadSize = 2)
 {
     if (backThreadTools == null)
     {
         backThreadTools = new SzThread("Back Thread", SzThread.ThreadType.Sys, backthreadSize);
         threads.TryAdd(backThreadTools.ID, backThreadTools);
     }
 }
Beispiel #2
0
 /// <summary>
 /// 添加一个线程模型到线程模型管理器里面
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 static public long GetThreadModel(SzThread model)
 {
     if (threads.TryAdd(model.ID, model))
     {
         return(model.ID);
     }
     return(0);
 }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tid"></param>
        /// <param name="taskbase"></param>
        static public void AddTimerTask(long tid, TimerTaskModel taskbase)
        {
            SzThread tm = GetThreadModel(tid);

            if (tm != null)
            {
                tm.AddTimerTask(taskbase);
            }
        }
Beispiel #4
0
        /// <summary>
        /// 取消一个任务,键不存在,返回null
        /// </summary>
        /// <param name="timerId"></param>
        static public TimerTaskModel RemoveTimerTask(long tid, long timerId)
        {
            SzThread thread = GetThreadModel(tid);

            if (thread != null)
            {
                return(thread.RemoveTimerTask(timerId));
            }
            return(null);
        }
Beispiel #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tid"></param>
        /// <returns></returns>
        static public bool RemoveThreadModel(long tid)
        {
            SzThread threadmodel = null;

            if (threads.TryRemove(tid, out threadmodel))
            {
                threadmodel.IsDelete = true;
                threadmodel          = null;
                return(true);
            }
            return(false);
        }
Beispiel #6
0
        /// <summary>
        /// 获取一个线程模型
        /// </summary>
        /// <param name="tid"></param>
        /// <returns></returns>
        static public SzThread GetThreadModel(long tid)
        {
            SzThread tm = null;

            if (tid == 0)
            {
                if (log.IsInfoEnabled())
                {
                    log.Info("艹艹艹艹线程id==0艹艹艹");
                }
            }
            threads.TryGetValue(tid, out tm);
            return(tm);
        }
Beispiel #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="threadType">线程类型</param>
        /// <param name="threadCount">线程数量</param>
        /// <returns></returns>
        static public long GetThreadModel(string name, SzThread.ThreadType threadType = SzThread.ThreadType.User, int threadCount = 1)
        {
            SzThread model = new SzThread(name, threadType, threadCount);

            return(GetThreadModel(model));
        }