Windows Services Help

D

Dave Harrington

Hi all -

I am very new with windows services, and I was wondering if I could get a
little guidance on them. Through online tutorials I've been able to
successfully build and install a "Hello World" version of a windows service.
What I'm looking to do is the following:

I have a database of basically Date/Time variables. Once an hour I want to
check these variables against the current time. When they are equal, I want
the windows service to send out an appropriate e-mail. When the process is
done, I'd like the program to sleep for another hour.

The database stuff I am familiar with, the sleep function and sending e-mail
through a windows service I am not. I was wondering if I could get some
guidance on this.

Also, where should I be doing my coding? Inside the Main() loop of the cs
file or inside the Windows service constructor (ex: MyService()).

Thanks in advance

Dave Harrington
(e-mail address removed)
 
G

Guest

Generally a service should have a timer, and the code goes in the timer's
Elapsed handler.



My SendMail method:

public static void
SendEmail
(
string Sender
,
string Recipient
,
string Subject
,
string Body
,
params System.IO.FileInfo[] Files
)
{
System.Web.Mail.MailMessage msg = new
System.Web.Mail.MailMessage() ;

if ( Files != null )
{
Body += string.Format
(
"\n\n{0} attached file{1}:"
,
Files.Length
,
Files.Length==1?"":"s"
) ;

foreach ( System.IO.FileInfo att in Files )
{
Body += "\n" + att.Name ;

if ( att.Exists )
{
msg.Attachments.Add ( new
System.Web.Mail.MailAttachment ( att.FullName ) ) ;
}
else
{
Body += " -- does not exist!" ;
}
}
}

msg.From = Sender ;
msg.To = Recipient ;
msg.Subject = Subject ;
msg.Body = Body ;

System.Web.Mail.SmtpMail.Send ( msg ) ;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top