473,379 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

How to detect System Time Change in CompactFramework?

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
3 6909
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Stephane Belzile | last post by:
Is there a way I can detect in vb.Net the power has switched to a UPS unit in case of power failure? Thanks
23
by: David McCulloch | last post by:
QUESTION-1: How can I detect if Norton Internet Security is blocking pop-ups? QUESTION-2a: How could I know if a particular JavaScript function has been declared? QUESTION-2b: How could I...
1
by: Patrick Dugan | last post by:
Are there any source code examples of how to place an icon in the system tray using vb.net and a smart device? I have found examples for vb.net but they do not work for smart device (PPC) Can...
1
by: charlies224 | last post by:
Hi, I am writting a software that requires me to make sure the Num Lock is always on and Caps Lock is always off. First, I know how to detect if Num Lock or Caps Lock is on or off (if...
2
by: eBob.com | last post by:
I've got the basics of an XML ini file working. I.E. I can stash away and retrieve user preferences. (Code below.) But how do I handle a new preference? Say I have A and B. And then I invent...
1
by: Steve.Goodman | last post by:
Appologies if this has already been asked, but after scanning the web and this news group I could find no decent solution. We have a windows App that calls a webservice, using this bit of basic...
3
by: José Joye | last post by:
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...
24
by: dE|_ | last post by:
I have started looking into scripts for screen size detect with the intention of using them to pick from a number of CSS style sheets tailored to the size. Is there a good reason why this is not...
1
by: Jeff | last post by:
I have located the following code and trying to change this so I know if the USB device has been inserted or removed. The problem I have is I alwayd get the Console.WriteLine("Usb removed") so I...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.