By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,887 Members | 954 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,887 IT Pros & Developers. It's quick & easy.

How to detect System Time Change in CompactFramework?

P: n/a
In my application (written for Compact Framework 2.0 ), I have to be
informed whenever a system Time change occurs (NTP, daylight saving, ...).
Under the normal framework, I'm able to use the
"Microsoft.Win32.SystemEvents.TimeChanged" event. However, this is not
available under CF.

Any help welcome!

- José
May 24 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
There is a system event that fires (actually a pair, one for time, another
for time zone). You can P/Invokce CeRunAppAtEvent[1] and get them. They
are also wrapped in the OpenNETCF Smart Device Framework[2].
--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World
www.OpenNETCF.com

[1] http://msdn2.microsoft.com/en-us/library/ms913956.aspx
[2]
http://blog.opennetcf.org/ctacke/Per...e3e7a9c3c.aspx

"José Joye" <Me@me.comwrote in message
news:46**********************@news.sunrise.ch...
In my application (written for Compact Framework 2.0 ), I have to be
informed whenever a system Time change occurs (NTP, daylight saving, ...).
Under the normal framework, I'm able to use the
"Microsoft.Win32.SystemEvents.TimeChanged" event. However, this is not
available under CF.

Any help welcome!

- José

May 24 '07 #2

P: n/a
Jose,
Here is some C# example code, I hope it helps:

[DllImport("coredll.dll", EntryPoint = "CreateEvent", SetLastError = true)]
private static extern IntPtr CreateEvent(IntPtr lpEventAttributes,
bool bManualReset,
bool bInitialState, string spName);

[DllImport("coredll.dll", EntryPoint = "WaitForSingleObject",
SetLastError = true)]
private static extern int WaitForSingleObject(IntPtr hHandle, UInt32
dwMilliseconds);

[DllImport("coredll.dll", EntryPoint = "CloseHandle", SetLastError =
true)]
private static extern bool CloseHandle(IntPtr hHandle);

[DllImport("coredll.dll", EntryPoint = "CeRunAppAtEvent",
SetLastError = true)]
private static extern bool CeRunAppAtEvent(string pszAppName, long
lwichEvent);

private const int NOTIFICATION_EVENT_TIME_CHANGE = 1;
private const UInt32 INFINITE = 0xFFFFFFFF;

public Form1()
{
InitializeComponent();
CeRunAppAtEvent("\\\\.\\Notifications\\NamedEvents \\MyTimeNamedEvent",
NOTIFICATION_EVENT_TIME_CHANGE);

Thread thread = new Thread(new ThreadStart(ThreadProc));
thread.Start();
}

private void ThreadProc()
{
IntPtr hEvent = CreateEvent(IntPtr.Zero, false, false,
"MyTimeNamedEvent");

WaitForSingleObject(hEvent, INFINITE);

MessageBox.Show("Time Event Occured");

CloseHandle(hEvent);
}

Rick D.
Contractor
"José Joye" wrote:
In my application (written for Compact Framework 2.0 ), I have to be
informed whenever a system Time change occurs (NTP, daylight saving, ...).
Under the normal framework, I'm able to use the
"Microsoft.Win32.SystemEvents.TimeChanged" event. However, this is not
available under CF.

Any help welcome!

- José
May 24 '07 #3

P: n/a
Thanks to both of you!

This is really usefull

- José
"dbgrick" <db*****@discussions.microsoft.coma écrit dans le message de
news: 74**********************************@microsoft.com...
Jose,
Here is some C# example code, I hope it helps:

[DllImport("coredll.dll", EntryPoint = "CreateEvent", SetLastError =
true)]
private static extern IntPtr CreateEvent(IntPtr lpEventAttributes,
bool bManualReset,
bool bInitialState, string spName);

[DllImport("coredll.dll", EntryPoint = "WaitForSingleObject",
SetLastError = true)]
private static extern int WaitForSingleObject(IntPtr hHandle,
UInt32
dwMilliseconds);

[DllImport("coredll.dll", EntryPoint = "CloseHandle", SetLastError
=
true)]
private static extern bool CloseHandle(IntPtr hHandle);

[DllImport("coredll.dll", EntryPoint = "CeRunAppAtEvent",
SetLastError = true)]
private static extern bool CeRunAppAtEvent(string pszAppName, long
lwichEvent);

private const int NOTIFICATION_EVENT_TIME_CHANGE = 1;
private const UInt32 INFINITE = 0xFFFFFFFF;

public Form1()
{
InitializeComponent();
CeRunAppAtEvent("\\\\.\\Notifications\\NamedEvents \\MyTimeNamedEvent",
NOTIFICATION_EVENT_TIME_CHANGE);

Thread thread = new Thread(new ThreadStart(ThreadProc));
thread.Start();
}

private void ThreadProc()
{
IntPtr hEvent = CreateEvent(IntPtr.Zero, false, false,
"MyTimeNamedEvent");

WaitForSingleObject(hEvent, INFINITE);

MessageBox.Show("Time Event Occured");

CloseHandle(hEvent);
}

Rick D.
Contractor
"José Joye" wrote:
>In my application (written for Compact Framework 2.0 ), I have to be
informed whenever a system Time change occurs (NTP, daylight saving,
...).
Under the normal framework, I'm able to use the
"Microsoft.Win32.SystemEvents.TimeChanged" event. However, this is not
available under CF.

Any help welcome!

- José

May 24 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.