Esempio n. 1
0
        /// <summary>
        /// 获取或创建
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public TimeStatus GetOrCreate(DateTime value)
        {
            string key = value.ToString("yyyyMMddHHmmss");

            lock (hashtable.SyncRoot)
            {
                if (!hashtable.ContainsKey(key))
                {
                    //如果总数大于传入的总数
                    if (hashtable.Count > 0 && hashtable.Count >= maxCount)
                    {
                        var firstKey = hashtable.Keys.Cast <string>().Min();
                        if (firstKey != null)
                        {
                            hashtable.Remove(firstKey);
                        }
                    }

                    hashtable[key] = new TimeStatus {
                        CounterTime = value
                    };
                }
            }

            return(hashtable[key] as TimeStatus);
        }
Esempio n. 2
0
        /// <summary>
        /// 获取或创建
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public TimeStatus GetOrCreate(DateTime value)
        {
            string key = value.ToString("yyyyMMddHHmmss");

            lock (hashtable.SyncRoot)
            {
                if (!hashtable.ContainsKey(key))
                {
                    //如果总数大于传入的总数
                    if (hashtable.Count > 0 && hashtable.Count >= maxCount)
                    {
                        var firstKey = hashtable.Keys.Cast<string>().Min();
                        if (firstKey != null) hashtable.Remove(firstKey);
                    }

                    hashtable[key] = new TimeStatus { CounterTime = value };
                }
            }

            return hashtable[key] as TimeStatus;
        }