Solved

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

Posted on 2009-05-07
4
704 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
[X]
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
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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Suggested Solutions

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…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 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