Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scheduler for aspx page. 3

Status
Not open for further replies.

whloo

Programmer
Apr 14, 2003
168
SG
Hi... I intend to create a web site that will process some data every 10 mins.
Is there any way i can schedule it in IIS? Or i need to get 3rd party software to do it?
Thanks!

Regards,
weihann.
 
dalchri,

Thanks for your answer.
But i need something that can go to call my aspx page like every 10 mins or so....
 
You might be more interested in a windows service with a timer:

Code:
using System;
using System.Configuration.Install;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.Remoting;
using System.ServiceProcess;

public class Service : System.ServiceProcess.ServiceBase {
   private System.Timers.Timer m_tmr = new System.Timers.Timer(600000);//6 minutes
	private System.ComponentModel.Container components = null;

	public Service() {
		this.InitializeComponent();
        m_tmr.Elapsed +=new System.Timers.ElapsedEventHandler(m_tmr_Elapsed);

	}

	static void Main() {
		ServiceBase[] ServicesToRun = new ServiceBase[] {new Service()};

		ServiceBase.Run(ServicesToRun);
	}

	private void InitializeComponent() {
		components = new System.ComponentModel.Container();
		this.ServiceName = "Timed Service";
	}

	protected override void Dispose(bool disposing) {
		if( disposing ) {
			if (components != null) {
				components.Dispose();
			}
		}
		base.Dispose(disposing);
	}

	protected override void OnStart(string[] args) {
   m_tmr.Enabled = true;
	}

	protected override void OnStop() {
   m_tmr.Enabled = false;
	}

		private void m_tmr_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {
   //Do what you would do on your aspx page here
		}

}

[RunInstaller(true)]
public class ServiceServiceInstaller : Installer {
	private ServiceInstaller HostInstaller;
	private ServiceProcessInstaller HostProcessInstaller;

	public ServiceServiceInstaller() {
		HostInstaller = new ServiceInstaller();
		HostInstaller.StartType = 
			System.ServiceProcess.ServiceStartMode.Automatic;
		HostInstaller.ServiceName = "Timed Service";
		HostInstaller.DisplayName = "10 Minute Timed Service";
		Installers.Add (HostInstaller); 
		HostProcessInstaller = new ServiceProcessInstaller();
		HostProcessInstaller.Account = ServiceAccount.User;
		Installers.Add (HostProcessInstaller);
	}
}

More info on windows services is here
If I remember right there is a project type called windows service that will set most of this up for you.
 
dalchri,

That's mean i need to write appl in order to run the scheduler?
Can i use web page instead?
It is because i am more comfortable with web page and i need to send email notification as well.
Thanks!

Regards,
weihann
 
A web page will time out before the 10 minutes are up.

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
chiph,

My idea is to write a scheduler that will call the aspx page in like 10 mins interval.
Each time the page will only need few secs to process the data.
Hence, it shouldn't have timeout problem?
Thanks!

Regards,
weihann.
 
I agree with the dalchri solution.
In the
Code:
       private void m_tmr_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {
   //Do what you would do on your aspx page here
        }
you should call and process the .aspx like here:
Code:
private void m_tmr_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
	WebRequest req = null;
	try
	{
		req = WebRequest.Create("[URL unfurl="true"]http://localhost/myweb/MyForm.aspx");[/URL]
		req.Method = "GET";
		req.Timeout = 20000; // seconds
	}
	catch (Exception ex)
	{
	}
}
If yow want to read the results then :
Code:
private void m_tmr_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
	WebRequest req = null;
	WebResponse rsp = null;
	StreamReader readStream = null;
	string strRec="";
	StringBuilder sb = new StringBuilder();
	try
	{

		req = WebRequest.Create("[URL unfurl="true"]http://localhost/myweb/MyForm.aspx");[/URL]
		req.Method = "GET";
		req.Timeout = 20000;
		rsp = req.GetResponse();
		Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
		readStream = new StreamReader( rsp.GetResponseStream(), encode );
		Char[] read = new Char[256];
		int count = readStream.Read( read, 0, 256 );
		while (count > 0) 
		{
			String str = new String(read, 0, count);
			sb.Append(str);
			count = readStream.Read(read, 0, 256);
		}
		strRec=sb.ToString();
		sb=null;
	}
	catch (Exception ex)
	{
	}
	
}
-obislavu-
 
RiverGuy,

How to make the web page to auto refresh every 10 mins?
Thanks!

Regards,
weihann
 
Code:
<HEAD>
<title>Your Page Title Here</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="[URL unfurl="true"]http://schemas.microsoft.com/intellisense/ie5">[/URL]
[b]<%Response.AddHeader("Refresh","600");%>[/b]
</HEAD>
 
Veep,

Thank you very much for your solution.
Simple and nice~
Not to forget a big thanks for dalchri, chiph, obislavu and RiverGuy for their contribution.
Thank you very much guys!

Regards,
weihann.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top