Click to See Complete Forum and Search --> : Global.asax doubt
pamai
03-18-2009, 03:10 AM
Hi!!
I'm developing a .NET web application and I would like to know how could I call automatically a method when the web server is restarted.
I've used the method Application_Start in Global.asax file, but Application_Start is fired when the application is accessed for the first time by any of the user's. Therefore, it's not valid for what I want.
Would it be posible to invoke the method without any user accessing the application? That would be perfect...
Any idea?
Help please!!!
Cheers!
ahmedel
03-22-2009, 11:34 PM
Indeed Application_Start will only be fired the first time the application is accessed by a user or by a web service call. A good suggestions is to create a Windows Service that calls a web method in your application. The Windows Service should be set to start automatically when the machine is started. This handles calling the method you want when the server is started. You also need to call this method when the web server restarts, which can happen without the machine itself restarting. I would recommend in that scenario to log something in your application's Application_End event that the Windows Service would trap and then the service would call the web method again on web server restart.
pamai
03-24-2009, 04:43 AM
Thanks for your answer.
And... How the windows service could trap it? Using a timer?
I don't know the potential of windows services...
ahmedel
03-25-2009, 09:52 PM
You could use a timer. Or, you could do log a file to a directory and have the service implement a FileSystemWatcher on that directory to watch for new/changed files and react accordingly.
pamai
03-26-2009, 04:54 AM
You could use a timer. Or, you could do log a file to a directory and have the service implement a FileSystemWatcher on that directory to watch for new/changed files and react accordingly.
Hi again,
But if Application_End event of Global.asax wrote in that file... when will the event (of FileSystemWatcher) that listens to the file change notifications be called?
I would like to call it when the web server is restarted... it's possible?
Cheers!
devx.com
Copyright Internet.com Inc. All Rights Reserved