How to detect System Time Change in CompactFramework?

J

José Joye

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é
 
G

Guest

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
 
J

José Joye

Thanks to both of you!

This is really usefull

- José
dbgrick said:
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 said:
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é
 

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

Top