Discussion:
System time change notification
(too old to reply)
Asher F.
2007-09-18 09:12:02 UTC
Permalink
Hopefully, I am posting this question in the appropriate newsgroup.
I have a question regarding detecting system time change in a server
application.
In a client/GUI application (i.e. application that has a WndProc) I can
handle the WM_TIMECHANGE message.
However, I have a server application (a Web application, Win32 Service
without a UI, etc…) where I need to detect the system time on such
application.
Is there something I am missing? What API should I use?
--
Asher.
Jeffrey Tan[MSFT]
2007-09-19 04:37:07 UTC
Permalink
Hi Asher,

To ensure my reply is a best practice recommendation, I have discussed with
some kernel expert internally.

They confirmed that we must create a window to get notification from
system. But since server application will run in Session 0 in Vista, I
suspect if Session 0 isolation feature in Vista will affect this solution.
Their comments below resolves my suspicion:

1. System broadcast messages like this will go to all topmost windows in
all terminal sessions, so Session 0 isolation feature in Vista will not
affect this solution.
2. You need to create a separate thread to pump messages for this window.
You can not rely on the service thread.
3. If you are using .Net in server application, you should PInvoke to the
Win32 APIs (RegisterClass, CreateWindow, Get/DispatchMessage) to create the
message loop and window instead of using .Net Winform message loops(this
may cause some problem).
4. Web applications are harder because they shouldn¡¯t maintain state.
Like background threads and windows. On the other hand, they shouldn¡¯t
maintain state, like knowledge about the previous system time.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Asher F.
2007-09-20 18:36:05 UTC
Permalink
Hello Jefry,
Thank you very much for your response.
I will implement it.
On the Web Application issue,you are correct that it shouldn't keep state.
I mention web application as an example for an application that doesn't
have a windows UI, it is not an actual issue for me.
Once again, thank you for your help.
--
Asher.
Post by Jeffrey Tan[MSFT]
Hi Asher,
To ensure my reply is a best practice recommendation, I have discussed with
some kernel expert internally.
They confirmed that we must create a window to get notification from
system. But since server application will run in Session 0 in Vista, I
suspect if Session 0 isolation feature in Vista will affect this solution.
1. System broadcast messages like this will go to all topmost windows in
all terminal sessions, so Session 0 isolation feature in Vista will not
affect this solution.
2. You need to create a separate thread to pump messages for this window.
You can not rely on the service thread.
3. If you are using .Net in server application, you should PInvoke to the
Win32 APIs (RegisterClass, CreateWindow, Get/DispatchMessage) to create the
message loop and window instead of using .Net Winform message loops(this
may cause some problem).
4. Web applications are harder because they shouldn¡¯t maintain state.
Like background threads and windows. On the other hand, they shouldn¡¯t
maintain state, like knowledge about the previous system time.
Hope this helps.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Jeffrey Tan[MSFT]
2007-09-21 01:59:47 UTC
Permalink
Hi Asher,

Glad to see my reply can help you.

Regarding Windows Forms is not designed for use in a non-interactive
context, this is documented in the MSDN link below:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.aspx
"Classes within the Windows Forms namespace are not supported for use
within a Windows service. Trying to use these classes from within a service
may produce unexpected problems, such as diminished service performance and
run-time exceptions."

So, p/invoke the Win32 GUI APIs is the correct solution. Attached is a
sample that captures WM_DEVICENOTIFICATION messages, which behave very much
the same as time change notifications. You can download the sample project
using Outlook Express not IE. If you fail to get it, please send an email
to: ***@online.microsoft.com(remove "online."), I will reply you with the
sample project.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Loading...