I have an ASP.NET web form application hosted on IIS.
In the app, I have a code snippet that should make some work on the background from the moment the application starts.
The problem is when I have created the singleton class and initialize it from Global.asax -> Application_Start(), The code runs only when the first user is connecting to the site.
How can I set it to run without any dependency from the user side? Any Idea?
The singleton class example:
public sealed class SingeltonBackgroundWork
{
private static SingeltonBackgroundWork updater = null;
private static Timer timer;
private SingeltonBackgroundWork()
{
//Milliseconds * Seconds * Minutes
timer = new Timer(1000 * 60 * 10);
timer.Elapsed += new ElapsedEventHandler(OnElapsed);
timer.AutoReset = true;
timer.Enabled = true;
}
private void OnElapsed(object sender, ElapsedEventArgs e)
{
//DO SOME WORK
}
public static void InitProcess()
{
if (updater == null)
{
updater = new SingeltonBackgroundWork();
}
}
}
Global.asax Application_Start():
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
SingeltonBackgroundWork.InitProcess();
}