How to set time and call web service in C# windows service program?

Posted on 2009-05-07
Last Modified: 2013-12-17

I have a windows service program which has a timer.

The timer needs to check the time everyday.

If (System.Time == 14:00)
// call a web service

But, I just found System.DateTime, but no Time.

How should I code it?

Question by:techques
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 12

Expert Comment

ID: 24332947
Here's how to get a nice string of the time

returns the TimeSpane where you can check for a particular time
LVL 12

Expert Comment

ID: 24332952
Sorry posted to quick, based on your example above I would use
            TimeSpan target = new TimeSpan(14, 0, 0);
            if (DateTime.Now.TimeOfDay == target)

Author Comment

ID: 24332960
Can I  write

if(System.DateTime.Now.Hour == 14)
LVL 12

Accepted Solution

wht1986 earned 50 total points
ID: 24333014

Featured Post

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question