Results 1 to 3 of 3

Thread: Converting my Forms based application to a service

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2007
    Posts
    159

    Question 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.

  2. #2
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    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.

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

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
  •  



Click Here to Expand Forum to Full Width