Solved

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

Posted on 2009-05-07
4
692 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
ID: 24332947
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
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)
            {
            }
0
 

Author Comment

by:techques
ID: 24332960
Can I  write

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

Accepted Solution

by:
wht1986 earned 50 total points
ID: 24333014
yup
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

947 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

18 Experts available now in Live!

Get 1:1 Help Now