Before 6 months I was working on one web portal, there was requirement to auto send mail to trial register users and that site was hosted on shared server and we are using sql server 2005 express edition. So there was only one option to create a scheduler in asp.net application.
At first time I faced so much problems, at finally I did like this
Note: Here I have tested the concept with database.
Srep1: Create a “Global.asax”.
Step2: Create one Class i.e DoSomeWork and write the code for insert in database like this and create a table in database with field Id,msg, and sentDate to check this concept
/// Summary description for DoSomeWork
public class DoSomeWork
public void DoSomeWorkWithDB()
//code for storing in database
// You can also write code for sending mail to some one on some condition
using (SqlConnection con = new SqlConnection("Data Source=.\\sqlexpress;Initial Catalog=Test;Integrated Security=True"))
using (SqlCommand cmd = new SqlCommand("Insert into tblMsg(msg) values(@msg)", con))
cmd.Parameters.AddWithValue("@msg", "This is the test message");
Step3: In “Application_Start “ method of Global.asax file, use the timer concept and assign the time interval to run that block of code like this.
<%@ Application Language="C#" %>
<%@ Import Namespace="System.Timers" %>
void Application_Start(object sender, EventArgs e)
// Code that runs on application startup
System.Timers.Timer myTimer = new System.Timers.Timer();
// Set the Interval to 10 seconds (10000 milliseconds).
myTimer.Interval = 10000;
myTimer.AutoReset = true;
myTimer.Elapsed += new ElapsedEventHandler(myTimer_Elapsed);
myTimer.Enabled = true;
public void myTimer_Elapsed(object source, System.Timers.ElapsedEventArgs e)
DoSomeWork obj1 = new DoSomeWork();
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)
Step3: Now run the asp.net application. It will insert data in database in every 10 second.
Note: You have some better idea to do this task then feel free to share with me. You are always welcome.