Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7945463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:52:26+00:00 2026-06-04T00:52:26+00:00

I am thinking about writing a windows service that will turn a certain functionality

  • 0

I am thinking about writing a windows service that will turn a certain functionality on or off at times specified by the user (using a configuration utility I will provide). Basically, the user would specify certain times that the PC would go into “work-only” mode (blocking Facebook and other distracting sites), and then when those times are up the PC will return to normal mode.

I have already come up with a few ways to create the “work-only” mode, but what I am struggling with is how to know when to go into and out of that mode. I don’t really want to work with threads and timers if I can avoid it since that seems like it would create an awful lot of overhead, so what I am looking for would be some way to either:

  • Hook in to the Windows API if there is some kind of timeChanged() event to check against
  • Use some sort of pre-built library for firing events at a specified time
  • Some other method that I haven’t thought of that is elegant and wonderful

Does anyone know the best way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:52:27+00:00Added an answer on June 4, 2026 at 12:52 am

    I think you can achieve it quite well with a Windows Service as you mentioned. In one of our productions systems we have a windows service (different core functionality as the requested) implemented in the way below that is running safely for almost three years now.

    Basically the aim of the following code is that the service executes certain method each time the internal timer (myTimer) wakes-up.

    Here below is a basic implementation. In this example your core functionality should be placed at the method EvalutateChangeConditions, that is supposed to be executed each 60 seconds. I would also provide a public method for your managing client(s) to know the current “working-mode”.

    public partial class MyService : ServiceBase
    {
        private System.Threading.Thread myWorkingThread;
        private System.Timers.Timer myTimer = new System.Timers.Timer();
    
        // [...] Constructor, etc
    
        protected override void OnStart(string[] args)
        {
            // Do other initialization stuff...
    
            // Create the thread and tell it what is to be executed.
            myWorkingThread = new System.Threading.Thread(PrepareTask);
    
            // Start the thread.
            myWorkingThread.Start();
        }
    
        // Prepares the timer, sets the execution interval and starts it.
        private void PrepareTask()
        {
            // Set the appropiate handling method.
            myTimer.Elapsed += new System.Timers.ElapsedEventHandler(myTimer_Elapsed);
    
            // Set the interval time in millis. E.g.: each 60 secs.
            myTimer.Interval = 60000;
    
            // Start the timer
            myTimer.Start();
    
            // Suspend the thread until it is finalised at the end of the life of this win-service.
            System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
        }
    
        void myTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            // Get the date and time and check it agains the previous variable value to know if
            // the time to change the "Mode" has come.
            // If does, do change the mode...
            EvalutateChangeConditions();
        }
    
        // Core method. Get the current time, and evaluate if it is time to change
        void EvalutateChangeConditions()
        {
            // Retrieve the config., might be from db? config file? and
            // set mode accordingly.
        }
    
        protected override void OnStop()
        {
            // Cleaning stuff...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm thinking about writing a small application that will help me mass rename files.
I'm thinking about writing a development tool that will support development for Android. I
I'm thinking about writing a program that asks the user to think of an
For about a year I have been thinking about writing a program that writes
I've been thinking about writing a text editor control that can edit text that
I'm thinking about building a Mac (maybe later Windows) application that would expose its
I want to build a windows service that will use a remote encoding service
I am thinking about writing a plugin for email application. It can be put
As a pet project, I was thinking about writing a program to migrate applications
I'm writing a simplified Pascal parser/interpreter and now I'm thinking about segmentation faults. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.