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

  • Home
  • SEARCH
  • 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 6057759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:31:27+00:00 2026-05-23T08:31:27+00:00

This is my first time working with windows service, and I am learning as

  • 0

This is my first time working with windows service, and I am learning as I go.
I am using VS 2010, Windows 7 to create a windows service that will have a timer. I have googled and browsed this site as well Use of Timer in Windows Service, Best Timer for using in a Windows service but I still am confused as to where to code for the timer in the windows service component

I have an OnStart method and OnStop method in the service1.cs class
Where would I code for the timer to execute the function (NOT start the windows service)?

  • 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-05-23T08:31:27+00:00Added an answer on May 23, 2026 at 8:31 am

    Below is an example of how to do this. It writes a message to the Application log (as seen in the Event Viewer) every 10 seconds until the service is stopped. In your case, put your periodic logic in the OnElapsedEvent() method.

    private System.Timers.Timer _timer = new System.Timers.Timer();
    
    protected override void OnStart(string[] args)
    {
        _timer.AutoReset = true;
        _timer.Interval  = 10000;  // 10 seconds
        _timer.Elapsed  += OnElapsedEvent;
        _timer.Start();
    }
    
    protected override void OnStop()
    {
        _timer.Stop();
    }
    
    private void OnElapsedEvent(object sender, ElapsedEventArgs e)
    {
        // Write an entry to the Application log in the Event Viewer.
        EventLog.WriteEntry("The service timer's Elapsed event was triggered.");
    }
    

    I’ve got a couple of detailed answers here at SO that might be of help as you start working with Windows services.

    • Creating a Windows service using C#
    • How to have your service install/uninstall itself without using InstallUtil.exe
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first time using joomla. I don't know if I'm using the
This is my first time with Web services. I have to develop web services
this is my first time posting here, I have a question which I have
This is the first time ever I'm using AJAX, and I want to do
this is my first time using StAX for parsing XML documents (still in the
I have a .NET Windows Service which spawns a thread that basically just acts
Disclaimer:It's my first time developing an app that will be on a tablet style
I'm working with caching and persistence for the first time. I have a user
I have written a windows service that uses the openpop mail client and retreives
I'm currently working on developing a windows service which will be deployed to all

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.