I had a project that consist of opening an Emailbox, read all the Spam and get the emails(from email of course), other parameters... and insert them in a Sql Database Table. I have a Button on a page where the admin of the site will go and click to start the reading. Problem: when it got to 350 emails, u got a Page Time out. Solution: Create a Timer for every 30 min , read the mail box. Now get rid of the Admin pain!! I will demonstrate how this can be done
To first start make sure you have the Global.asax file in your Project. I am using asp.net 3.5 and Linq to Sql for this particular Website I create a file SpamReader.cs inside of my Utils Project.
public class SpamReader {
public SpamReader()
{
}
public void _timer_Elapsed(object sender, ElapsedEventArgs e) {
ReadSpamComplaint();
}
public void ReadSpamComplaint()
{
string sServer = "pop.mysite.com";
string sUserName = "username";
string sPassword = "password";
GetMyMails(sServer, sUserName, sPassword, false);
}
private static void GetMyMails(string sServer, string sUserName, string sPassword, bool bSSLConnection)
{
}
}
It is about it. Hold on, one more thing to do. Now it is time to use the Timer class. Very easy...Open your Global.asax.cs and in Application start call the Spamreader class..
protected void Application_Start(object sender, EventArgs e)
{
SpamReader spam = new SpamReader();
Timer zTimer = new Timer();
zTimer.Elapsed += new ElapsedEventHandler(spam._timer_Elapsed);
zTimer.Interval = 900000;//every 15 min
zTimer.Start();
}
and set the timer to what ever you want. my case 15min=15x60minx60sec and add 000 for the Miliseconds.. That 's about it. I hope you enjoyed it. Leave a comment please.