我在Global.asax上有以下代碼。它通常會產生電子郵件報警。我的問題是,我已經設置每24小時發送一封電子郵件,但代碼每10分鐘發送一次電子郵件。我已設置:自動電子郵件機制
HttpContext.Current.Cache.Add(CacheItemKey, "Test", null,
DateTime.MaxValue, TimeSpan.FromHours(24)
但stll應用程序發送的電子郵件的每個10分鐘。我也嘗試了幾分鐘。
我的代碼:
private const string CacheItemKey = "CacheFromMe";
public void CacheIRemovedCallback(string key,
object value, CacheItemRemoved reason)
{
HitmyPage();
// Do the service works
DosomeWork();
}
private const string myPageUrl = "myurl.aspx";
private void HitmyPage()
{
WebClient myclient = new WebClient();
myclient.DownloadData(myPageUrl);
}
protected void Application_BegintheRequests(Object sender, EventArgs e)
{
// If the dummy page is hit, then it means we want to add another item
// in cache
if (HttpContext.Current.Request.Url.ToString() == myPageUrl)
{
// Add the item in cache and when succesful, do the work.
RegistermyCacheEntries();
}
}
private void DosomeWork()
{
DoEmailStuff();
AnotherEmailStuff();
}
private void DoEmailStuff()
{
// Statment For Sending The Email under conditions
}
private void AnotherEmailStuff()
{
// Another Statment for Sending Email
}
void Application_Start(object sender, EventArgs e)
{
RegistermyCacheEntries();
}
private bool RegistermyCacheEntries()
{
if (null != HttpContext.Current.Cache[CacheItemKey]) return false;
HttpContext.Current.Cache.Add(CacheItemKey, "Test", null,
DateTime.MaxValue, TimeSpan.FromHours(24),
CacheItemPriority.Normal,
new CacheIRemovedCallback(CacheIRemovedCallback));
return true;
}
你試過24d嗎? –
我已經完成了你對會議記錄所說的話。我有1440分鐘,每10分鐘發一次。我將其更改爲207360分鐘,並且每隔10分鐘發送一次,並且每20分鐘發送一次。沒有人錯誤地訪問我從該代碼調用的虛擬Url。唯一有權訪問的應用程序僅爲應用程序 – focus
「CacheIRemovedCallback」中'reason'參數的值是什麼? –