-
Apr 30th, 2012, 03:20 AM
#1
Thread Starter
Addicted Member
Converting my Forms based application to a service
I have an application that I created a while ago. It's a forms based application that runs on one of our servers at work. The app works well, BUT at the moment, requires someone to manually run it, which means having the admin account always logged in, but having the server locked.
Although it's a forms based application, for the majority of the time I don't need to see the forms, so can I safely make this run as a service (by adding the appropriate code), and hiding the forms?
Also, is there some code I can put in to test whether the instance of the program was started as a service or from a user double clicking on the icon? If so, I'd like the user initiated instance to run with the forms visible.
Thanks
If my post helped you, please rate it. Thanks.
-
Apr 30th, 2012, 08:05 AM
#2
Re: Converting my Forms based application to a service
I use the compile type to decide to show the form (a debug info form only), or to just run the service like so:
Code:
<MTAThread()> Sub Main()
#If DEBUG Then
gfrmDebug = New frmDebug 'I hold a copy as I update it with stats
Application.Run(gfrmDebug)
#Else
'Run as a service, let it deal with everything, I might have more than 1, so use a loop, again you can remove the loop and just run 1 copy
Dim ServicesToRun() As System.ServiceProcess.ServiceBase
ServicesToRun = New System.ServiceProcess.ServiceBase() {New clsServiceMain} 'This clsServiceMain is just a class that Inherits System.ServiceProcess.ServiceBase
For Each Service As System.ServiceProcess.ServiceBase In ServicesToRun
Service.CanPauseAndContinue = True
Service.CanShutdown = True
Service.AutoLog = True
Next
System.ServiceProcess.ServiceBase.Run(ServicesToRun)
#End If
End Sub
Not exactly what you asked for, but you can use the bones. An alternative is to use command arguments, so when run as a service you can use MyExeName.exe /AsService
There is no method that I know of to tell you dynamically.
-
Apr 30th, 2012, 11:44 AM
#3
Re: Converting my Forms based application to a service
A service is something you have the server "start" when the system boots and it usually waits for some event to happen and then processes said event.
A console app is one that you would run as a scheduled task on some regular basis.
Which one is it?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|