views:

86

answers:

4

I develop a website and I have this problem:

The registered users on the website should put a (date & time) field, and when the current date will be the same of this date a function (that I developed) should be called.

How can I do that?

Your Faithfully.

A: 

Are you talking about a scheduled task? I.e. you want to record some data from a user which includes a date, and when the date entered comes around then carry out a task.

If so you will need more that just asp.net as there is no facility to do anything like this as part of an asp.net website running in IIS. One the website side of things you would simply record the data in a database. You would then need a windows service or similar that periodically polls the database to see if the data on the record is the same as today and then carry out the action.

Ben Robinson
A: 

From your comment it sounds like the SMS text could possibly be sent in the future? If this is the case you should write a service or an exe that is run on a scheduled interval. I wouldn't depend on the website to handle this.

Gary L Cox Jr
A: 

You're going to want to create a windows service to check your database periodically. The OnStart function and main executing loop of your service will look like this:

protected override void OnStart(string[] args)
{ 
    var worker = new Thread(DoWork);
    worker.Name = "MyWorker";
    worker.IsBackground = false;
    worker.Start();
}

private void checkLoop()
{
    while(1)
    {
        //Run Query to check if any database records exist where registered   
        //date time > current date time
        checkDBAndSendNotification();

        //Make service inactive for 10 seconds
        Thread.Sleep(10000);
    }
}

This article should help you a bit on coding/setting up the windows service: http://www.codeproject.com/KB/dotnet/simplewindowsservice.aspx

Be sure to download the example code in that article and use it as your starting point.

vdoogs
Thank you for your support.But this operation will be heavy and extra overload on the server.So, isn't there a way that the windows service listens on on the date and when the date will be the same of this date the send task will be done.
kassar
Hmm. You could schedule a task... Check this library: http://www.codeproject.com/KB/cs/tsnewlib.aspx . So what you would do is use that library to schedule a task, and have that task run an executable that runs the checkDBAndSendNotification() function. If you think this is a satisfactory answer please accept my solution.
vdoogs
A: 

I agree, you will have to write a service that runs on the server, that checks the dates every x minutes. I would recommend that you have an unsent table, that holds the messages that have not been sent, with the send times. The service can check the unsent table every 10 minutes, and when the time is before before now, send the message and then move the record to a sent table.

Johnny DropTables
Thank you for your support.But this operation will be heavy and extra overload on the server.So, isn't there a way that the windows service listens on on the date and when the date will be the same of this date the send task will be done.
kassar