예제 #1
0
 public static bool SetUsedPreName(string name)
 {
     lock (PreNamesManager._Mutex)
     {
         PreNameItem preNameItem = null;
         if (PreNamesManager._PreNamesDict.TryGetValue(name, out preNameItem))
         {
             if (preNameItem.Used <= 0)
             {
                 preNameItem.Used = 1;
                 PreNamesManager._UsedPreNamesQueue.Enqueue(preNameItem);
                 return(true);
             }
         }
     }
     return(false);
 }
예제 #2
0
        /// <summary>
        /// 添加一个项到列表中
        /// </summary>
        /// <param name="name"></param>
        /// <param name="sex"></param>
        /// <param name="used"></param>
        public static void AddPreNameItem(string name, int sex, int used)
        {
            PreNameItem preNameItem = new PreNameItem()
            {
                Name = name,
                Sex  = sex,
                Used = used,
            };

            lock (_Mutex)
            {
                _PreNamesDict[name] = preNameItem;
                if (0 == sex) //男性
                {
                    _MalePreNamesList.Add(preNameItem);
                }
                else //女性
                {
                    _FemalePreNamesList.Add(preNameItem);
                }
            }
        }
예제 #3
0
        public static void AddPreNameItem(string name, int sex, int used)
        {
            PreNameItem preNameItem = new PreNameItem
            {
                Name = name,
                Sex  = sex,
                Used = used
            };

            lock (PreNamesManager._Mutex)
            {
                PreNamesManager._PreNamesDict[name] = preNameItem;
                if (0 == sex)
                {
                    PreNamesManager._MalePreNamesList.Add(preNameItem);
                }
                else
                {
                    PreNamesManager._FemalePreNamesList.Add(preNameItem);
                }
            }
        }
예제 #4
0
 public static void ClearUsedPreNames()
 {
     lock (PreNamesManager._Mutex)
     {
         int count = 50;
         while (PreNamesManager._UsedPreNamesQueue.Count > 0 && count-- >= 0)
         {
             PreNameItem preNameItem = PreNamesManager._UsedPreNamesQueue.Dequeue();
             if (null != preNameItem)
             {
                 PreNamesManager._PreNamesDict.Remove(preNameItem.Name);
                 if (0 == preNameItem.Sex)
                 {
                     PreNamesManager._MalePreNamesList.Remove(preNameItem);
                 }
                 else
                 {
                     PreNamesManager._FemalePreNamesList.Remove(preNameItem);
                 }
             }
         }
     }
 }
예제 #5
0
 /// <summary>
 /// 清除使用过的名字(每次只清除50个, 防止占用太长的CPU)
 /// </summary>
 public static void ClearUsedPreNames()
 {
     lock (_Mutex)
     {
         int         count       = 50;
         PreNameItem preNameItem = null;
         while (_UsedPreNamesQueue.Count > 0 && count-- >= 0)
         {
             preNameItem = _UsedPreNamesQueue.Dequeue();
             if (null != preNameItem)
             {
                 _PreNamesDict.Remove(preNameItem.Name);
                 if (0 == preNameItem.Sex) //男性
                 {
                     _MalePreNamesList.Remove(preNameItem);
                 }
                 else //女性
                 {
                     _FemalePreNamesList.Remove(preNameItem);
                 }
             }
         }
     }
 }