I almost feel dirty having to ask this question, but I am stuck in an unfortunate position.
We are rushing to provide a very quick and dirty interim solution. We have a need to run 2 3rd party applications (fortunately not at the the same time). The applications rely heavily on the time. One requires GMT while the other requires BST (British Summer Time). So in British Summer Time GMT and BST are an hour different.
We would like to write a little app that can change the system time before launching the relavent app. This is proving to be a little more difficult than is sounds. The main problem being that you can't ever know that the time is correct before change it. The Laptop may have been shutdown without our app quiting properly (ba开发者_Go百科ttery issues etc).
We are able to synch the time with the server over a network. But I have been unable to identify when this has happened. I've found that there's a WM_TIMECHANGED windows message that's broadcasted when the time is set. So this could be used.
We could also show a message on login and get the user to verify the starting time, but users very quickly grow blind to this, or fail to realise the importance.
A working example of this would be: 1: Laptop set to BST (Current time is 13:00) 2: Open app one (GMT) time will change to 12:00 3: Close app one (GMT) time will change to 13:00 4: Open app one (BST) time will remain at 13:00 5: Close app one (BST) time will change to 13:00
Does anyone have any clever ideas?
run one app in a VM
Could you synchronise the time with the server within the app? then you would know it has been synchronised and that the time was correct. Since you know the time zone of the server, you could then adjust the time depending on which app was running.
EDIT: Since you can't always access the network you have to assume to time is correct (i.e. you can't change it) if the apps are calling GetLocalTime (instead of GetSystemTime) then you could change the timezone instead of the time to adjust the result of GetLocalTime.
If the apps are calling GetSystemTime (there fore you have to change the time) you would need a marker (such as a file on disk) that told your app you had changed the time and hadn't managed to change it back (due to unexpected termination). This way you would always know that the time was either correct (no marker present) or the time was shifted (marker present)
Not actually a solution, but we worked around having both apps in the end.
Thanks
精彩评论