用于在global.asax中接收电子邮件的异步方法

时间:2019-03-04 17:19:11

标签: c# async-await

我已经定义了一种用于接收电子邮件的静态方法:

public static class Receiver
{
    public static void EmailReceiving()
    {

    }
}

在Global.asax中,我定义了一个计时器,该计时器每15分钟接收一次新邮件。

Global.asax:

    public class MvcApplication : System.Web.HttpApplication
{
    static System.Timers.Timer timer;
    static System.Timers.Timer emailRecieverTimer;

    protected void Application_Start()
    {
        emailRecieverTimer = new System.Timers.Timer();
        emailRecieverTimer.Enabled = true;
        emailRecieverTimer.Interval = 900000;
        emailRecieverTimer.Start();
        emailRecieverTimer.Elapsed += HandleEmailRecieverTimerElapsed;

    }


    public void HandleEmailRecieverTimerElapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
        Receiver.EmailReceiving();
    }

}

我可以将其定义为异步吗?由于它当前正在运行,因此该程序接收电子邮件的速度会很慢

0 个答案:

没有答案
相关问题