我已经定义了一种用于接收电子邮件的静态方法:
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();
}
}
我可以将其定义为异步吗?由于它当前正在运行,因此该程序接收电子邮件的速度会很慢