Trying to change timezones on the fly

  • Thread starter Thread starter Youraputz
  • Start date Start date
Y

Youraputz

I'm currently writing some c# code for the .net cf on CE 5.0, part of
this requires the user to be able to change the date/time/timezone.
After doing a bit of research I've successfully set the date, time and
timezone of the system, however my application does not recieve the new
timezone info unless I restart it. According to pinvoke.net this is
the expected behavior because the .net environment is not updated, so
all subsequent calls to DateTime are using the old timezone info. What
I need to do is make this update (if possible).

What I'm currently trying is to use SendMessage() function from
coredll.dll in order to broadcast a message that will cause this
update. Is this appropriate? possible? If so perhaps I'm closer than I
think. Here is my code:

[DllImport("coredll.dll")]
private static extern int SendMessage(IntPtr hWnd, uint msg, int
wParam, int lParam);

// Alert of change
IntPtr HWND_BROADCAST = 0xFFFF;
uint WM_SETTINGCHANGE = 0x001A;
SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0);

The obvious issue to me is that both wParam and lParam are 0, and
perhaps they are not supposed to be. Any advice would be much
appreciated.
 
There's nothing you can do about it. The CLR loads the timezone/dst info at
startup and that's it. Your best bet is to never use DateTime.Now, but
instead P/Invoke to GetLocalTime, which will reflect the changes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top