Solved

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

Posted on 2009-05-07
4
688 Views
Last Modified: 2013-12-17
Hi

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?


0
Comment
Question by:techques
  • 3
4 Comments
 
LVL 12

Expert Comment

by:wht1986
Comment Utility
Here's how to get a nice string of the time
DateTime.Now.ToShortTimeString()

Otherwise
DateTime.Now.TimeOfDay
returns the TimeSpane where you can check for a particular time
0
 
LVL 12

Expert Comment

by:wht1986
Comment Utility
Sorry posted to quick, based on your example above I would use
            TimeSpan target = new TimeSpan(14, 0, 0);
            if (DateTime.Now.TimeOfDay == target)
            {
            }
0
 

Author Comment

by:techques
Comment Utility
Can I  write

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

Accepted Solution

by:
wht1986 earned 50 total points
Comment Utility
yup
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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.   …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now