DateTime.UtcNow 在 Silverlight 应用程序中的可靠性如何?
我有一个 silverlight 应用程序,用户将在各个时区运行该应用程序。
这些应用程序在启动时从服务器加载数据,然后将其缓存到IsolatedStorage中。
当我更改服务器上的数据时,我希望能够更改“上次更新时间”,以便所有 silverlight 客户端下次下载最新数据他们检查这个日期。
但是,我对如何处理时区问题有点困惑,因为如果服务器位于纽约并且更新时间设置为 2010-01-01 17:00:00,西雅图的客户将其与当地时间2010-01-01 14进行比较:00:00 它将不会更新,并将继续提供旧数据三个多小时。
我的解决方案是始终以 UTC 时间发布更新时间,而不是服务器上的时间,然后使用检查 Silverlight 应用程序检查强>日期时间.UtcNow 。
这是否像听起来那么简单,或者是他们的问题,例如,计算机上的时区设置不正确,因此 SilverlightApp 不会报告正确的 UTC 时间。 任何人都可以根据经验说,像这样使用 DateTime.UtcNow 进行缓存刷新在所有情况下都有效吗?
如果 DateTime.UtcNow 不可靠,我将只使用增量< /strong>“DataVersion”整数,但在其他情况下,降低时区同步将有助于彻底了解如何在 silverlight 应用程序中解决此问题。
I have a silverlight application which users will be running in various time zones.
These applications load their data from the server upon start up, then cache it in IsolatedStorage.
When I make changes to the data on the server, I want to be able to change the "last updated time" so that all silverlight clients download the newest data the next time they check this date.
However, I'm a bit confused as to how to handle the time zone issue since a if the server is in New York and the update time is set to 2010-01-01 17:00:00 and a client in Seattle checks compares it to its local time of 2010-01-01 14:00:00 it won't update and will continue to provide old data for three more hours.
My solution is to always post the update time in UTC time, not with the time on the server, then make the Silverlight app check with DateTime.UtcNow.
Is this as easy as it sounds or are their issues with this, e.g. that timezones are not set correctly on computers and hence the SilverlightApp does not report the correct UTC time. Can anyone say from experience how likely it is that using DateTime.UtcNow like this for cache refreshing will work in all cases?
If DateTime.UtcNow is not reliable, I will just use an incremented "DataVersion" integer but there are other scenarios in which getting time zone sychronization down would make it useful to thoroughly understand how to solve this in silverlight apps.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DateTime.UtcNow 与客户端系统上的时钟一样可靠。因此,问题完全独立于 Silverlight 或 .NET,问题是您对客户端计算机上的系统时钟有多信任?
您需要权衡机器用户可能因为没有正确设置时区而在其机器上错误设置时间的风险。这种风险完全是人性的。
使用递增版本号只有一个缺点,您需要先检索当前值,然后才能设置新值。如果这不是问题,那么就继续这样做并消除您在时区周围可能存在的 FUD。
DateTime.UtcNow is as reliable as the clock on the client system. So the question is entirely independent of Silverlight or .NET, the question is how much do you trust the system clock on the client machines?
You need to weigh the risk that a user of a machine may have incorrectly set the time on their machine because they have not set the time zone correctly. This risk is entirely human in nature.
Using an incrementing version number only has one downside, you need to first retrieve the current value before you can set a new one. If that isn't a problem then go with that and eliminate the FUD you might have around time zones.