Timer Control in APS.NET ?

A

abhishek007p

HI,

i am using visual web developer for .net 2.0.

does .NET 2.0 comes with a timer control, i was unable to find it in
the IDE, where is it ?


thanks,
Abhishek
 
J

Juan T. Llibre

Peter Bromberg posted this Rob Howard sample a few days ago :

using System;
using System.Web;
using System.Threading;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace BlackbeltBLL {
public class BackgroundService : IHttpModule {
static Timer timer;
int interval = 5000;
public String ModuleName {
get { return "BackgroundService"; }
}

public void Init(HttpApplication application) {
// Wire-up application events
if (timer == null)
timer = new Timer(new TimerCallback(ScheduledWorkCallback), application.Context, interval, interval);
}

public void Dispose() {
timer = null;
}

private void ScheduledWorkCallback (object sender) {
HttpContext context = (HttpContext) sender;
Poll(context);
}

void DoSomething (HttpContext context) {
}

#region DB Poll
void Poll (HttpContext context) {
SqlConnection connection = new SqlConnection(ConfigurationSettings.AppSettings["Northwind"]);
SqlCommand command = new SqlCommand("SELECT * FROM changenotification", connection);
SqlDataReader reader;
string key = ConfigurationSettings.AppSettings["SqlDependency"];
connection.Open();
reader = command.ExecuteReader();
while (reader.Read()) {
string tableKey = String.Format(key, reader["Table"]);
if (context.Cache[tableKey] != null) {
int changeKey = int.Parse( context.Cache[ String.Format(key, reader["Table"])].ToString() );
if (changeKey != int.Parse(reader["ChangeID"].ToString() ))
context.Cache.Remove(tableKey);
}
}
connection.Close();
}
#endregion
}
}

---000---
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top