我的問題是,我必須在特定的時間每天發送郵件,有沒有辦法在asp.net中做到這一點? 給我適當的建議。 注意:我不想運行Windows應用程序或Windows調度程序。我在Global.asax的如何在asp.net中爲郵件創建調度程序?
private static CacheItemRemovedCallback OnCacheRemove = null;
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
AddTask("Remoder", 5);
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
}
private void AddTask(string name, int seconds)
{
OnCacheRemove = new CacheItemRemovedCallback(CacheItemRemoved);
HttpRuntime.Cache.Insert(name, seconds, null,
DateTime.Now.AddSeconds(seconds), Cache.NoSlidingExpiration,
CacheItemPriority.NotRemovable, OnCacheRemove);
}
public void CacheItemRemoved(string k, object v, CacheItemRemovedReason r)
{
// do stuff here if it matches our taskname, like WebRequest
// re-add our task so it recurs
AddTask(k, Convert.ToInt32(v));
}
public void Remoder()
{
HttpContext.Current.Response.Write("Hello Start");
}
但我想調用特定的功能,它有可能嗎? –
是的,看到註釋/ /如果它與我們的任務名稱相匹配,就像WebRequest一樣 - 用函數調用替換它。例如'if(k ==「callFunction」){callFunction();}' – Widor
這裏是代碼,我使用 –