Creating a web service that uses a timer

B

Brian Bischof

I've researched web services but have no luck finding anything but the most
basic tutorial. I want to have a service that runs certain checks at
specified intervals during the day. So after the service starts a timer will
be triggered to see if its time to run the checks.

My problem is that the web service links I found are so simplistic that they
tell me nothing. They just put some code in the OnStart and OnStop events
and write to the log file. I need a service that runs while the computer is
turned on. Just using the OnStart events are pretty useless. Is there a link
which helps me understand how to do what I want? Here are some questions
that come to my mind:

1) Do I need a Timer control to trigger the event?
2) If Windows triggers the service periodically, is there an event I should
use that gets called?
3) It appears that the .NET service calls another process in the Main()
method. Is this a seperate DLL that I have to build?
4) If the service runs continuously, how do I keep it from using up
resources?

Thanks for any help/web links.

Bria
 
D

djmc

In my asp.net application (which has web services), I use a timer such as
the one outlined below. I put this in the Global.asax file. Is this kinda
what you're looking for?

//In Global.asax
private Timer tMyTimer;

void Application_Start(Object sender, EventArgs e)
{
int iTimerPeriod = 60000; // run every 1 minute
TimerCallback callback;

callback = new TimerCallback(MyBackgroundProcess.RunThisMethod);
tMyTimer = new Timer(callback, null, 0, iTimerPeriod);
}


//In your MyBackgroundProcess.cs
public class MyBackgroundProcess
{

public static void RunThisMethod(object state)
{
//run your check here
}
}
 

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

Top