Help creating Windows Service .net studio 2005

T

teejayem

I am having problems creating a Windows Service using Visual Studio
2005.

Code as follows:-


Imports System.IO
Imports System.Net.Mail


Public Class Service1


Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set
things
' in motion so your service can do its work.
Timer1.Start()
End Sub


Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop
your service.
Timer1.Stop()
End Sub


Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
email()
Dim test as new streamwriter("C:\test")
End Sub


Sub email()
Dim myMessage As New MailMessage("(e-mail address removed)",
"(e-mail address removed)", _
"test", "test")


Dim mysmtpclient As New SmtpClient("exchange03")
mysmtpclient.Send(myMessage)
End Sub
End Class


I have installed the service using the installutil
started the service using services manager in administritive tools
but
nothing happens.
i have tried doing various tasks within the timer tick procedure but
the service will not do anything. Am i missing something?? I know
my
code works as i have tested the code in a normal windows app. and
yes
i am uninstalling the service, rebuilding the project then
reinstlling
the service.


This is frustrating!!!!


Any help is mich appreciated.


Cheers, Tom.
 
M

Mr. Arnold

This is frustrating!!!!


Any help is mich appreciated.

I would suspect that the Service application has terminated along the way,
and you don't know it. I'll assume you are using try/catch/blocks on code in
critical areas like on the OnStart and Onstop and any other areas needed,
along with an Event log to capture error messages.

If you are using a NT based O/S like XP, then you can enable the Messenger
Service and use the Netsend command in the code to send messages to the
machine the Service is running on. The Netsend command will pop a message
box on the screen that you will have to reply to, but it can be used to send
messages to yourself as to just where you are at in the Service code that
can help you in your debugging process.
 
T

teejayem

<snipped>
<snip>

My problem was that I was using the wrong timer. I was using the
System.Windows.Forms.Timer class rather than the System.Timers.Timer
class.
 

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