예제 #1
0
 /// <summary>
 /// 创建事件,如果对象池中有则无需创建
 /// </summary>
 /// <param name="type"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 internal static ThreadEvent Create(string type, object data = null)
 {
     if (pools.Count > 0)
     {
         ThreadEvent e = pools[pools.Count - 1];
         e.type = type;
         e.data = data;
         return(e);
     }
     return(new ThreadEvent(type, data));
 }
예제 #2
0
 public static ThreadEvent Create(string type)
 {
     if (pools.Count > 0)
     {
         ThreadEvent e = pools[pools.Count - 1];
         e.id   = ID++;
         e.type = type;
         pools.RemoveAt(pools.Count - 1);
         return(e);
     }
     return(new ThreadEvent(type));
 }
예제 #3
0
 public ThreadEvent ReadEvent()
 {
     while (readId < maxId)
     {
         if (list.ContainsKey(readId + 1))
         {
             ThreadEvent e = list[readId + 1];
             readId++;
             return(e);
         }
         else
         {
             readId++;
         }
     }
     return(null);
 }
예제 #4
0
        public static List <ThreadEvent> GetAllEvent(int threadId)
        {
            List <ThreadEvent> list = new List <ThreadEvent>();

            for (int i = 0; i < threads.Count; i++)
            {
                if (threads[i] != threadId)
                {
                    ThreadEventList threadEventList = threadList[threads[i]][threadId];
                    ThreadEvent     e = threadEventList.ReadEvent();
                    while (e != null)
                    {
                        list.Add(e);
                        e = threadEventList.ReadEvent();
                    }
                }
            }
            return(list);
        }
예제 #5
0
 /// <summary>
 /// 把事件放回对象池
 /// </summary>
 /// <param name="e"></param>
 internal static void Release(ThreadEvent e)
 {
     pools.Add(e);
 }
예제 #6
0
 public void AddEvent(ThreadEvent e)
 {
     list.Add(e.Id, e);
     maxId = e.Id;
 }
예제 #7
0
 public void AddEvent(int threadId, ThreadEvent e)
 {
     ThreadEventList.GetList(Id, threadId).AddEvent(e);
 }