Beispiel #1
0
 private static void Collect(object threadID)
 {
     while (true)
     {
         try
         {
             var cacheValues = cache.Values;
             cacheValues = cacheValues.OrderBy(p => p.Item3).ToList();
             foreach (var cacheValue in cacheValues)
             {
                 if ((cacheValue.Item3 - DateTime.Now).Seconds <= 0)
                 {
                     Tuple <string, object, DateTime> item;
                     cache.TryRemove(cacheValue.Item1, out item);
                 }
             }
             Thread.Sleep(taskInterval * 60 * 1000);
         }
         catch (Exception ex)
         {
             Dispose();
             GCThreadProvider.AddThread(new ParameterizedThreadStart(Collect));
         }
     }
 }
Beispiel #2
0
 static MemoryCache()
 {
     try
     {
         GCThreadProvider.AddThread(new ParameterizedThreadStart(Collect));
     }
     catch (Exception err)
     {
         throw new CacheException(err.Message, err);
     }
 }