Skip to content

System.Runtime.Caching.MemoryCacheStatistics.SetTrimStats DivideByZeroException #1423

@StephenMolloy

Description

@StephenMolloy

From VS Feedback for .Net 4.5.2 - https://developercommunity.visualstudio.com/content/problem/539608/net-452-systemruntimecachingmemorycachestatisticss.html

  1. private readonly MemoryCache messageStore = new MemoryCache("Message Store");
  2. Thread 1: this.messageStore.Add(messageId, message, new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.UtcNow.AddMinutes(5), RemovedCallback = arguments => { if (arguments.RemovedReason == CacheEntryRemovedReason.Expired) { // Logging ... } } })
  3. Timer Thread (System.Threading.Timer):this.messageStore.GetCount();
  4. Thread 2: this.messageStore.Get
  5. Thread Pool (TPL): this.messageStore.Remove

System.DivideByZeroException: Es wurde versucht, durch 0 (null) zu teilen. bei System.Runtime.Caching.MemoryCacheStatistics.SetTrimStats(Int64 trimDurationTicks, Int64 totalCountBeforeTrim, Int64 trimCount) bei System.Runtime.Caching.MemoryCacheStatistics.CacheManagerThread(Int32 minPercent) bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) bei System.Threading.TimerQueueTimer.CallCallback() bei System.Threading.TimerQueueTimer.Fire() bei System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() bei System.Threading.ThreadPoolWorkQueue.Dispatch()

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions