Need real time of day in WinForms app, not computer's time

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

We have an Windows application that is date/time sensitive and we need to get the real time of day somewhere. We can't rely on the user's computer time (DateTime.Now) because they could change it. The network administrator suggested Network Time Protocol (NTP). Also he's going to look into creating our own internal NTP server. With that in mind, does C#/WinForms support something like this? Are there any other ways to get the time from a consistent source?
 
You might find the link below useful.
http://www.codeproject.com/csharp/ntpclient.asp?df=100&forumid=2012&exp=0&select=644865

--
Tim Wilson
..Net Compact Framework MVP
{cf147fdf-893d-4a88-b258-22f68a3dbc6a}
sandman said:
We have an Windows application that is date/time sensitive and we need to
get the real time of day somewhere. We can't rely on the user's computer
time (DateTime.Now) because they could change it. The network administrator
suggested Network Time Protocol (NTP). Also he's going to look into
creating our own internal NTP server. With that in mind, does C#/WinForms
support something like this? Are there any other ways to get the time from
a consistent source?
 
Since you're going across the network anyway, why not create a web service
to return the time from a central server?

Brandon

sandman said:
We have an Windows application that is date/time sensitive and we need to
get the real time of day somewhere. We can't rely on the user's computer
time (DateTime.Now) because they could change it. The network administrator
suggested Network Time Protocol (NTP). Also he's going to look into
creating our own internal NTP server. With that in mind, does C#/WinForms
support something like this? Are there any other ways to get the time from
a consistent source?
 
Matt Berther said:
Why not use DateTime.UtcNow, which is the current UTC time?

It's only the current UTC time if it's accurate - the OP is concerned
that the user may have changed the time manually. This isn't (as far as
I understand the question) about time zones, but the time itself.
 
Two ways I would go about this:

1. Have the network administrator set up the server to be the authoritative time server and then to set its time from: http://support.microsoft.com/default.aspx?scid=kb;en-us;262680&Product=win2000
& http://support.microsoft.com/default.aspx?scid=kb;en-us;216734&Product=win2000
and then in a logon script, the computer sets its time. Then, you could have your app run a batch or script to update its time before any of the time sensitive transactions occur. You need to catch errors here because you have to have certain rights to change time.


The second way would be for each computer to set its time directly to one of the external time servers. My server uses 129.6.15.28 as the time server (nist.gov) and then one of my apps that has some record changes and activity logs uses the server to update the time. The client also required that the backend server show the time of the server and then the client in the table just in case the user was still able to get around it. They went so far to have the script file encoded so the user didn't know what they were looking at.
 
The network administrator is fairly confident that he can configure one of our servers to be a NTP server. The problem is that the users don't all have access to the web so I can't use an external NTP server. But the web-site that Tim pointed me too looks promising. Hopefully, the combination will work. Thanks everybody!
 
I downloaded the code and rebuilt it with .NET 2003. On my Win2000 machine, it runs fine. But my laptop, running XP Prof, gets a SocketException with an error that says "An existing connection was forcibly closed by the remote host". I debugged into it and it's on a call to UpdClient.Receive(). Does this make any sense? I can ping the server so I know I'm connecting.

----- Tim Wilson wrote: ----

You might find the link below useful
http://www.codeproject.com/csharp/ntpclient.asp?df=100&forumid=2012&exp=0&select=64486

--
Tim Wilso
..Net Compact Framework MV
{cf147fdf-893d-4a88-b258-22f68a3dbc6a
sandman said:
We have an Windows application that is date/time sensitive and we need t
get the real time of day somewhere. We can't rely on the user's compute
time (DateTime.Now) because they could change it. The network administrato
suggested Network Time Protocol (NTP). Also he's going to look int
creating our own internal NTP server. With that in mind, does C#/WinForm
support something like this? Are there any other ways to get the time fro
a consistent source
 
I'm not really sure what's going on in that situation. I only have testing
access to a Windows 2000 machine right now. You might want to post to the
forum at the bottom of the page, below the article
(http://www.codeproject.com/csharp/ntpclient.asp?df=100&forumid=2012&exp=0&s
elect=644865). If you cannot find any help there you might consider going to
the authors home page (http://www.dataman.ro/), from there you can see the
section for the SNTP client (http://www.dataman.ro/sntp/default.asp), and at
the bottom is a "contact" link that you might try.

--
Tim Wilson
..Net Compact Framework MVP
{cf147fdf-893d-4a88-b258-22f68a3dbc6a}
sandman said:
I did some more research and found that the error code is 10054
(WASCONNRESET) if that helps. But it doesn't make sense that the host is
doing anything because the app runs under Win2000.
 
Back
Top