.NET application to service

fkheng

Centurion
Joined
May 8, 2003
Messages
155
Location
Malaysia
I started off a .NET project by choosing it at the wizard as a Windows Application. However, I now think that I would like it to be a Windows Service. Is there any way I can convert it to a windows service?
 
You could inherit your main class from ServiceBase, add OnStart method, and OnStop.
But it wont be that easy :), because i think youll have to change some otehr things too.
 
er........i don't really uinderstand wat u mean, i'm actually still a newbie, could you elaborate a bit more for me?
 
Im assuming you have a form class.
Go to the top of it, you should see this:
Visual Basic:
Inherits Windows.Forms.Form
Change it to:
Visual Basic:
Inherits System.ServiceProcess.ServiceBase
This will make it a service.
Now, you need to override the OnStart and OnStop.
Visual Basic:
Protected Overrides Sub OnStart(ByVal args() As String)
       'in here you put the code that tells the service what to do
End Sub

Protected Overrides Sub OnStop()
       'tells the service what to do when it stops
End Sub
From there you just call your methods, functions, or whatever you call :)
 
Back
Top