I have a Singleton class named CacheState. This class publishes many events. The CacheState has a System.Timers.Timer that loops and triggers all these events.
Then in my asp.net application, I subscribe to these events during Application_Start. The Timer in CacheState is also started during this time:
protected void Application_Start(object sender, EventArgs e)
{
CacheState.Instance.ProductChangedEvent += (objSender, argsE) => ProductService.ReloadProductCache(false);
CacheState.Instance.PageflexChangedEvent += (objSender, argsE) => ProductService.ResetPageflexCache(false);
CacheState.Instance.DeliveryChangedEvent += (objSender, argsE) => PricingRuleService.ResetDeliveryMethodsCache(false);
CacheState.Instance.UIItemChangedEvent += (objSender, argsE) => TemplateService.ResetUIItemsCache(false);
CacheState.Instance.ProductAttributeChangedEvent += Instance_ProductAttributeChangedEvent;
CacheState.Instance.Start();
}
I've read that C# Events can cause memory leaks. So, can anyone tell me if I'm doing this wrong?
Thanks.
See Question&Answers more detail:os