开发者

how to create scheduler application for mail in asp.net?

开发者 https://www.devze.com 2023-03-25 03:26 出处:网络
my question is, I have to send mail at specific time daily, is there any way to do this in asp.net ? give me appropriate suggestions.

my question is, I have to send mail at specific time daily, is there any way to do this in asp.net ? give me appropriate suggestions. Note : i don't want to run windows application or windows scheduler.

code which i used in global.asax

 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");
    }


Have a look at http://quartznet.sourceforge.net/


I think this technique from Jeff Himself is what you need: https://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/


I tried the hack ... turning your application global.asax into a virtual scheduler. It was my choice, because my server admin department simply refuses (because they don't understand) to do it with windows, or a database job.

If I had my druthers though, I'd use a database "job", since sql-server can send mail directly. Not sure what db you're using, but if you have the necessary access, I'd recommend looking for a solution like that, instead of trying to fool your asp.net app.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号