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 { Dispose(); GCThreadProvider.AddThread(new ParameterizedThreadStart(Collect)); } } }
static MemoryCache() { try { GCThreadProvider.AddThread(new ParameterizedThreadStart(Collect)); } catch (Exception err) { throw new CacheException(err.Message, err); } }