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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:39:41+00:00 2026-05-31T20:39:41+00:00

I run an application as a service on a server and then I have

  • 0

I run an application as a service on a server and then I have multiple clients connect to that service. I display the exact server time on each of the client Window form application and because of that I need a mechanism to detect any time change on the server so that I can send it to the client to display.

Looking over the MSDN I found SystemEvents.TimeChanged , I thought I’m in luck because when testing with the code below with Visual Studio everything works great:

SystemEvents.TimeChanged += new EventHandler(SystemEvents_TimeChanged);

static void SystemEvents_TimeChanged(object sender, EventArgs e)
    {
        //Occurs when user manually changes the time or due to
        //daylight saving time.  Server will issue its latest time
        //to all the clients so time can be adjusted.
    }

Unfortunately when I run this as a service, this event will never get fired because looking at the fine print on MSDN, the TimeChanged event only fires in an application with a message pump (aka it has to have a running form) active. It works in Visual Studio because it has a form when I run it as a non service mode.

I can correct this by checking the option “Allow service to interact with desktop” but that kind of defeats the purpose of me trying to run the application as a service.

I could create a timer tick event in the application to check for time change, let’s say every 10 seconds or so but this is a big overhead just to check for a random time change that occurs on the server machine twice or maybe 3 times per year.

So anyone know a C# event that trigger on time change that works in an application that does not have message pump going? I’m surprise if Microsoft does not include an event that works this way

Thank you.

  • 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-31T20:39:42+00:00Added an answer on May 31, 2026 at 8:39 pm

    Thank you all for your inputs, they certainly pointed me in the right direction. I was able to solve my issue and I figure to put them here for anyone down the road that find them helpful.

    So in my main program where I run the service, it has to be a sub class of ServiceBase.

    In my main function I spawned a separate thread as follow:

    new Thread(RunMessagePump).Start();
    
    private void RunMessagePump()
    {
      Application.Run(new HiddenForm())
    }
    

    This Hidden form is exactly what its name say, it is a simple form that is remain hidden by the code this.ResumeLayout(false) under its Intiailaizecomponent() code.

    Within this form’s FormLoad event you can declare any System event. In my case I have

    private void HiddenForm_Load(object sender,EventArgs e)
    {
      SystemEvents.timeChanged += new EventHandler(SystemEvents_TimeChanged);
    }
    

    Voila, this works out beautifully, and I think I will use this form load event to capture any SystemEvents I want to use down the road.

    Cheers.

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

Sidebar

Related Questions

I have VB application that requires visual service pack 6 to run , now
I have a long-lived server application that is designed to run with minimal downtime
Working on a service application in Delphi 5 that is intended to run on
I am writing an application in C# that needs to run as a service
We've got a scheduling application running that calls a WCF service to run nightly
I have WCF client server application, and create msi setup projects for both projects.
I currently have a TCP server application written in .Net that receives and submits
I have created an application which has a client (WPF) and the Server (WCF),
I have a WCF service that is hosted in a windows application. The service
Can we have any mechanism other then window service by which we ensure that

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.