1

I have a process which runs at midnight which send birthday notification mails.This only needs to run once a day, here is my code in Global.asax file

private const string DummyPageUrl = "http://localhost:4865/automatic/dummy.aspx";
private const string DummyCacheItemKey = "dummmmyyy";
void Application_Start(object sender, EventArgs e)
{
    RegisterCacheEntry();

}
private void RegisterCacheEntry()
{
    if (null != HttpContext.Current.Cache[DummyCacheItemKey]) return;
    HttpContext.Current.Cache.Add(DummyCacheItemKey, "Test", null,       Cache.NoAbsoluteExpiration,
       TimeSpan.FromHours(1), CacheItemPriority.NotRemovable,
        new CacheItemRemovedCallback(CacheItemRemovedCallback));
}
public void CacheItemRemovedCallback(string key, object value, CacheItemRemovedReason reason)
{
    DoWork();
    HitPage();
}
private void HitPage()
{
    System.Net.WebClient client = new System.Net.WebClient();
    client.DownloadData(DummyPageUrl);
}
private void DoWork()
 {

}
protected void Application_BeginRequest(object sender, EventArgs e)
{
    if (HttpContext.Current.Request.Url.ToString() == DummyPageUrl)
    {
        RegisterCacheEntry();
    }
}
4

0 回答 0