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 7492397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:25:49+00:00 2026-05-29T16:25:49+00:00

I have been recently challenged with writing a Windows Service. I needed to periodically

  • 0

I have been recently challenged with writing a Windows Service. I needed to periodically request a URL and check its availability. For this I decided to initialize a timer in OnStart method of the service and do all the work in timer_Tick event.

My first approach was using System.Windows.Forms.Timer and its Tick event. I chose for it, because of the tutorial that I was reading. Somehow I could not make the service work. It installed and started without problems, but it would not fire the event (I attached the debugger to the process and saw that it was not fired). I thought that maybe using Forms timer in Windows service is not a good idea, so I decided to switch to System.Timers.Timer and utilize its Elapsed event. This did not work either. I tried both mentioned approaches in a Windows Forms application and they both worked.

After some digging, I found this site: http://weblogs.asp.net/sibrahim/archive/2004/01/13/58429.aspx on which the blogger advices to utilize yet another timer: System.Threading.Timer. I changed the approach for the third time and BOOM it started working like a charm.

My question is: why can’t I use the other timers in Windows services and why is it so difficult to find an information about it?

  • 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-29T16:25:50+00:00Added an answer on May 29, 2026 at 4:25 pm

    The System.Windows.Forms.Timer timer uses the message pump of the UI to marshal the tick event, a service doesn’t run a message pump by default so without a little extra work the System.Windows.Forms.Timer timers will not work.

    The System.Timers.Timer is a server-based timer and raises an event on the thread you create it on (I think). If this isn’t working, perhaps you aren’t starting the timer or the timer runs on a thread that immediately ends (as in, nothing is keeping the thread alive so it finishes).

    http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx

    The System.Threading.Timer timer uses a callback that runs on a ThreadPool thread and isn’t tied to the message pump at all, hence this worked.

    When you run Application.Run(myForm) in a WinForms project, that call also runs up the message pump, this manages UI messages. The windows timer you mention is a UI component and expects the message pump to be running in order to cause the tick event to occur on the UI thread.

    Take a look here for running a message pump in a Windows Service:

    Message pump in .NET Windows service

    Further reading:

    http://support.microsoft.com/kb/842793

    In conclusion, I’d just go with the System.Threading.Timer class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a (hopefully) really simple question - I have been told recently that
This is something I have been doing recently and was wondering if others do
I have been recently writing a UDP server for a 2D shooter game I
I have been recently familiarizing myself with the windows desktop sharing api, and i
I have recently been getting an error in the Windows Forms designer of VS2010SP1
I have been recently (and repeatedly) asked by customers about MIPS needed to run
I have been recently digging into Mobile Programming, I practically tried out the J2ME
I have been recently testing my app in a strict mode to detect disk
I have been recently trying to deploy a C# application on a computer that
I have been an iphone developer for a while, and I have recently been

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.