Search code examples
c#processsynchronizationsystem-clock

How to sync system clock with global date/time?


My system clock is going crazy randomly at any moment and changing the system clock's date/time to a random one. It's not the lithium battery nor a virus because I checked. Also it's not something from the Windows.System.Time itself.

I want to create a process that will, on an interval, check to see if the system clock's date/time matches the global date/time and if not, it would sync.

I need this to run in the background. I am not even sure if a Windows process is correct way to accomplish this. I am open to any other solutions as well.


Solution

  • Create a new c# empty project. Click on the project and go to Properties change the output type to Windows Application (This will remove the console).

    Create a new class example: Example.cs

    Write the static entry point eg:

    public class Example
    {
        static void Main(string[] args)
        {
    
        }
    }
    

    Insert your code in the Main routine.

    This will create a process that contains no console/window/service.

    I'm guessing this is what you want.