0

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.

Code Maverick
  • 19,231
  • 10
  • 57
  • 111
egy
  • 133
  • 7
  • You could create a windows service to do this http://msdn.microsoft.com/en-us/library/zt39148a(v=vs.110).aspx – DeanOC Feb 02 '14 at 22:59
  • A Windows GUI app is a process too. When you run Notepad, you run a process. What exactly do you mean. You need to spell it out. – David Heffernan Feb 02 '14 at 22:59
  • Sorry David, I just edited the question. Thanks for the quick reply. Anything else should I know ? – egy Feb 02 '14 at 23:01
  • 3
    I guess you are looking to write a Windows service. However, don't write a service to sync time. The system can already do it and it is surprisingly hard to do well. Very likely your code will get it wrong. – David Heffernan Feb 02 '14 at 23:03
  • So you say the better option is Windows service and also in the same time not to write a service just to sync time. If you are right, then, what do I write ? – egy Feb 02 '14 at 23:07
  • Well, there seems to me to be little point in writing a service to perform a function that the OS already does better than you can – David Heffernan Feb 03 '14 at 01:20
  • The reason I am doing this is the system's clock is going crazy randomly at any moment (i.e. changing the date and time to a random one). And no, it's not the lithium battery nor a virus because I checked those. Also it's not something from the Windows.Time itself. It's Weird and I need to find a solution. Thanks for your previous answer, David. – egy Feb 03 '14 at 22:43
  • You simply need to update your question with your clarifications, not the comments. You should delete the comment. I'll update your question. – Code Maverick Feb 05 '14 at 21:08
  • I think it much more important to find out **why** your system clock is “going crazy”. – Dour High Arch Feb 05 '14 at 21:14
  • Your question has been updated and it is should now be ***much more clear*** as to what you are wanting. However, this still might not enough because at this point you are simply asking for a solution. You need to try to do this yourself and then edit your question adding in the code that you've tried if it's still not working. – Code Maverick Feb 05 '14 at 21:20

1 Answers1

0

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.

Xela
  • 2,210
  • 1
  • 15
  • 28
  • Yes It's as simple as I want. Thanks. And by the way, do you know how can I fetch current time from a server ? You don't have to type a lot. Just give me articles or links to read. – egy Feb 03 '14 at 22:39
  • Have a look at this: http://stackoverflow.com/questions/1008111/get-the-exact-time-for-a-remote-server – Xela Feb 04 '14 at 01:33