473,406 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Windows Services Help

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
dh*********@alum.bu.edu

Nov 17 '05 #1
1 943

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 ) ;
}

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: =?Utf-8?B?dmlzaHJ1dGg=?= | last post by:
This code works fine in Windows Application. In Windows Application, I am able to zip the image files properly and it totally contains 900MB My problem is the same code which I used in my Windows...
2
by: =?Utf-8?B?dmlzaHJ1dGg=?= | last post by:
Hi, I have 2 applications running, one Windows application project and the other windows services project. I want to call my Windows application in my windows services. I want to run them as...
1
by: =?Utf-8?B?dmlzaHJ1dGg=?= | last post by:
Hi, I have 2 applications running, one Windows application project and the other windows services project. I want to call my Windows application in my windows services. I want to run them as...
5
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.