pravz
pravz

Reputation: 235

how do i can run my window service on mentioned days in a week

how can make my window service should run only on mentioned days only

Ex: my window service service have to be run MONDAY - FRIDAY, remaining SATURDAY and SUNDAY dynamically SERVICES should to be stop

can any one help me on this part, how to do this ...>>>

Upvotes: 0

Views: 2907

Answers (6)

Paul
Paul

Reputation: 948

@pravz why do you keep asking about code behind? Is this an ASP.NET application? If so, I think you should probably re-write your question with that information and repost. So far to me this doesn't sound like you are actually running a service. If you want a service to run that way your best bet is to write it into code as previously suggested. If it's just a console app, I would throw it in Scheduled Tasks.

Upvotes: 0

David Fox
David Fox

Reputation: 10753

If you really want to accomplish this in a Windows Service, you should setup a System.Threading.Timer object with a callback that confirms your time frames.

The timer can be set to run every 24 hours (86,400 seconds)

protected override void OnStart(string[] args)
{
    // this will start a timer when your service starts
    // the 3rd argument will run DoStuff(object) immediately and again in 24 hours
    timer = new System.Threading.Timer(new System.Threading.TimerCallback(DoStuff), null, 0, 86400 * 1000);
}

Then, in the callback DoStuff check the time, day, etc

public static void DoStuff(object objectState)
{
    DateTime now = DateTime.Now;
    if(now.DayOfWeek != DayOfWeek.Saturday && now.DayOfWeek != DayOfWeek.Sunday)
    {
        // do some stuff
    }
}

Upvotes: 1

Haris Hasan
Haris Hasan

Reputation: 30097

You should use window scheduler

See this http://www.sourcedaddy.com/windows-7/scheduling-the-task-scheduler.html If you want to know how

Upvotes: 4

Oliver Weichhold
Oliver Weichhold

Reputation: 10296

I'm using Quartz.Net in production and I'm pleased with the ease of use and reliability. You could basically let your service run continously but invoke specific tasks within the service configured at schedules of your liking.

Upvotes: 1

Thorsten Hans
Thorsten Hans

Reputation: 2683

Moving the logic into a simple application and invoking it by using a windows scheduled task.

Upvotes: 0

Marcus Granström
Marcus Granström

Reputation: 17964

Sorry if I don't understand your question properly but I am assuming that you want to run a scheduled program in Windows. If that is the case I would go for Windows Task Scheduler. It can be found in the control panel.

Upvotes: 0

Related Questions