コード例 #1
0
 private void ProcessCountData()
 {
     this._LastClearDate = DateTime.Now;
     while (true)
     {
         try
         {
             TimeSpan span;
             foreach (KeyValuePair <string, List <T> > pair in this._DataGroupList)
             {
                 int count = pair.Value.Count;
                 if ((count >= this._BatchCount) || (((span = (TimeSpan)(DateTime.Now - this._LastClearDate)).Minutes >= this._ClearMinutes) && (count > 0)))
                 {
                     List <T>             list = new List <T>();
                     ReaderWriterLockSlim slim = this.objConfigWriterLockSlimHelper.CreateLock(pair.Key);
                     slim.EnterWriteLock();
                     try
                     {
                         list.AddRange(pair.Value);
                         pair.Value.Clear();
                     }
                     finally
                     {
                         slim.ExitWriteLock();
                     }
                     if (list.Count > 0)
                     {
                         this._batchActionAdd(pair.Key, list);
                     }
                 }
             }
             span = (TimeSpan)(DateTime.Now - this._LastClearDate);
             if (span.Minutes >= this._ClearMinutes)
             {
                 this._LastClearDate = DateTime.Now;
             }
             Thread.Sleep(this._SleepMilliseconds);
         }
         catch (Exception exception)
         {
             EventLogHelper.WriterLog("定时定量批量操作", exception);
             Thread.Sleep(this._SleepMilliseconds);
         }
     }
 }