"Application" Variable Web Application

How do I create an "agent" who will be running automatically when a page in the web application is run? "Agent" runs only once a day, no more. In fact this web page is accessed by many people per day.
Here are some solutions:
1. Save the date in the database. Weaknesses: would be too frequent connection to the database server, the server Will be busy ...
2. Save the date in the Application variable. Put this code into your default page :

if (!IsPostBack)
{
if (Application["date"] != null)
{
if (Convert.ToDateTime(Application["date"]) != DateTime.Today)
{
Application["date"] = DateTime.Today;
//do something
}
}
else
{
Application["movingdate"] = DateTime.Today;
//do something
}
}

Application variables are very similar to the Session. Session will run out if the web page was closed. Meanwhile, the Application would not run out even though the web page is closed. So in the Application, the values ​​will be stored on, except for Servers to die then it will return an empty / null.

Ok, may it helps

Thanks

No comments:

Post a Comment