Run as Application or Service

Microsoft Visual studio pro 2008 (full p...
May 28, 2010 at 07:50:28
Specs: Windows 7
Hi, I've been trying to create an application in
VB.NET that could run
either as a common application (offering a user
interface and all) or
as a Service.
I don't know if I'm in the right path or what, I've
been investigating and
got to this part (Service1.Designer):

Imports System.ServiceProcess
Imports System.IO

<Global.Microsoft.VisualBasic.CompilerServic
es.DesignerGenerated(
)> _
Partial Class Service1
Inherits
System.ServiceProcess.ServiceBase

'UserService overrides dispose to clean up
the component list.

<System.Diagnostics.DebuggerNonUserCode(
)> _
Protected Overrides Sub Dispose(ByVal
disposing As Boolean)
Try
If disposing AndAlso components
IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub

' The main entry point for the process
<MTAThread()> _

<System.Diagnostics.DebuggerNonUserCode(
)> _
Shared Sub Main()

Dim flines As String() =
File.ReadAllLines("config.txt")
If flines.Length > 0 Then
If flines(0) = "form" Then
Dim form1 As Form1 = New Form1
form1.Show()
Else
Dim ServicesToRun() As
System.ServiceProcess.ServiceBase

' More than one NT Service may run
within the same
process. To add
' another service to this process,
change the following line
to
' create a second service object.
For example,
'
' ServicesToRun = New
System.ServiceProcess.ServiceBase () {New
Service1, New
MySecondUserService}
'
ServicesToRun = New
System.ServiceProcess.ServiceBase() {New
Service1}


System.ServiceProcess.ServiceBase.Run(Ser
vicesToRun)
End If
Else
MsgBox("No config file")
End If

End Sub

'Required by the Component Designer
Private components As
System.ComponentModel.IContainer

' NOTE: The following procedure is required
by the Component
Designer
' It can be modified using the Component
Designer.
' Do not modify it using the code editor.

<System.Diagnostics.DebuggerStepThrough()
> _
Private Sub InitializeComponent()
'
'Service1
'
Me.ServiceName = "Service1"

End Sub

End Class

To get to this part, I've created a windows
service project, added a
form Form1 witch would be the one called if
the initializacion
demanded that it should run as an application,
and a file that would
let me choose whether I want to start as an
application or a service.
The thing is that starting as a service,
everything runs well, but when
it has to start as an application, it just shows
the form for about half
a second and then ends completely.

What am I doing wrong? Should I start with a
different approach and
in this case, which?
Any help would be really appreciated, thanks
in advance.

Gonzalo


See More: Run as Application or Service

Report •


#1
June 1, 2010 at 02:15:29
You can try Application as Service by Eltima Software. Eltima offers 14 days free trial version.

Report •

#2
June 1, 2010 at 06:09:00
But I neet to develop the application to be stand alone, not using
a third party tool to make it run as an service.
I read a post here that explained how to do it for C#, tried to
reproduce it, and the application, when starting as common
application and not a service, would finnish immediately.

Report •

#3
October 26, 2010 at 11:59:03
We started out moding our code to be a service but there were problems on Server 2008 that we didn't anticipate. Ended up going with AlwaysUp
http://www.coretechnologies.com/pro...

Report •

Related Solutions


Ask Question