PDA

View Full Version : Scheduling Events on the server


christrinder
07-12-2007, 12:04 AM
Hi all. I've been round the houses trying to set-up some sort of automatic, scheduling process that could fire off some of my ASP.NET code to run a series of a routines... but I just can't find a way that works.

I have a number of sites that run on my (windows) box so I've finally decided to call a single web service (therefore accessible from every domain) on each and every session_end (within the global file). The code I've written to call this web service is as follows:

HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(myURL);
objRequest.ContentType = "application/x-www-form-urlencoded";
objRequest.Method = "POST";
objRequest.Timeout = 2000;
objRequest.Credentials = CredentialCache.DefaultCredentials;

StreamWriter myWriter = new StreamWriter(objRequest.GetRequestStream());
myWriter.Write("");
myWriter.Close();

objRequest.GetResponse();

This all seems to work, but it can't be the best way. There's no guarantee that a session_end event will be raised within some time periods, and then there will be other times when many are raised etc. Also, I can't work out how to make the above ascyronise (can't spell it!) so speed it up.

SOOOOOOOOO.... does anybody know of a better solution because this feels very piece-meal.

Thanks,
Chris :confused:

SouthwaterDave
07-17-2007, 08:30 PM
You did say "my (windows) box" so I assume you have full access to your computer.

You could write a C# or VB.NET program and schedule it to run as a Windows Scheduled Task. You should not find this difficult if you already code in ASP.NET. It could call a web service if that is what you want or it could perform the required task directly.