I created a task to run every minute and decided to put it in the Application_Start
event in Global.asax
file to execute as soon as the application is started. When I run it (without debugging and in debug mode), It doesn't fire up.
I tried to put it in Session_Start
event just to make sure it's not from the markup of the Global.asax
file and it worked perfectly. But unfortunately, It has to be when the Application starts and not when a session starts.
This is my Global.asax (ASP.NET 2.0, VS2008) below:
<%@ Application Language="C#" Inherits="Microsoft.Practices.CompositeWeb.WebClientApplication" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="TaskManager" %>
<script runat="server">
private TaskScheduler _scheduler = null;
void Application_Start(object sender, EventArgs e)
{
XmlDocument xml = new XmlDocument();
xml.Load(Server.MapPath(@"\Config\tasks.config"));
XmlNodeList nodes = xml.SelectNodes("Tasks/Task");
this._scheduler = new TaskScheduler(nodes);
this._scheduler.StartTasks();
}
void Application_End(object sender, EventArgs e)
{
this._scheduler.StopTasks();
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
}
</script>