Results 1 to 9 of 9

Thread: Services in VB.NET standard

  1. #1

    Thread Starter
    New Member russgreen's Avatar
    Join Date
    Apr 2003
    Posts
    12

    Services in VB.NET standard

    Does anyone know of a macro or way of enabling Windows service projects to be created in VB.NET standard? Thomas Erdösi has written a fantastic macro to enable new projects to be compiled to dll's.

    If not the would someone be kind enough to create a new blank windows service project for me?

    Russ

  2. #2

    Thread Starter
    New Member russgreen's Avatar
    Join Date
    Apr 2003
    Posts
    12
    I've created a service and installer and installed my service. It show up in the list of services now but when trying to start it it takes too long and the status is stuck on starting.

    Any ideas?

    I've posted the project in its current state here.

    Russ

  3. #3
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    I haven't written any services, but it seems very likely that you need to investigate the ServiceController component:
    ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemserviceprocessservicecontrollerclasstopic.htm

    "Represents a Windows service and allows you to connect to a running or stopped service, manipulate it, or get information about it."

  4. #4
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    That isn't what you wanted at all, is it. I'm trying to figure out service installation/removal also, or maybe someone else already has done it and will post your answer.

  5. #5
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    Got it. Read:
    ms-help://MS.VSCC/MS.MSDNVS/vbcon/html/vbwlkwalkthroughcreatingwindowsserviceapplication.htm

    I followed its instructions exactly and was rewarded with the following attached project. The output of the project (two projects actually) is a) a service and b) an installer package. I ran the installer package, my toy service showed up in the services list (right-click My Computer -> Manage...) and the service started/stopped, as well as stuck an event in the event log.

    Something a bit tricky (although you sound like you got past this: When you provide username/password, if you are installing on your local machine, the format for username is COMPUTERNAME\username.

    Hope it helps.
    Attached Files Attached Files

  6. #6
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    Project files for the installer:
    Attached Files Attached Files

  7. #7

    Thread Starter
    New Member russgreen's Avatar
    Join Date
    Apr 2003
    Posts
    12
    Thanks, I did get past this stage and I have narrowed down the problem.

    I get my service working fine now with the on start

    VB Code:
    1. Dim watcherThread As Thread = New Thread(AddressOf listener)
    2.  
    3. Protected Overrides Sub OnStart(ByVal args() As String)
    4.         WriteToLog("logs\webproxy.log", "Service started")
    5.         watcherThread.Start()
    6.     End Sub

    the listener code is this

    VB Code:
    1. Private Sub listener()
    2.         Dim tcplistener As New TcpListener(port)
    3.         tcplistener.Start()
    4.  
    5.         WriteToLog("logs\webproxy.log", "Listening on port " & port.ToString)
    6.  
    7.         'While True
    8.         ' Dim socket As Socket = tcplistener.AcceptSocket()
    9.         '  Dim webproxy As New WebProxy(socket)
    10.         '   Dim thread As New Thread(New ThreadStart(AddressOf webproxy.runproxy))
    11.         '    thread.Start()
    12.         'End While
    13.     End Sub

    The problem code has been commented out. How else can I continuously monitor the tcp port for sockets?

    My WriteToLog isn't working in a service either. Any ideas? It works in all my winforms and console apps.

    Is there a service equivalent of Application.Startuppath?

    VB Code:
    1. Public Sub WriteToLog(ByVal Filename As String, ByVal Comment As String)
    2.         Dim sw As System.IO.StreamWriter
    3.         Try
    4.             sw = New System.IO.StreamWriter(Filename, True)
    5.             sw.WriteLine(Date.Now & "     " & Comment)
    6.             sw.Flush()
    7.         Catch e As Exception
    8.         Finally
    9.             If Not sw Is Nothing Then sw.Close()
    10.         End Try
    11.     End Sub

    Russ

  8. #8
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    TcpListener is kind of out of my bailiwick. Have you read:
    ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfSystemNetSocketsTcpListenerClassTopic.htm
    ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemnetsocketstcpclientclassgetstreamtopic.htm
    and
    ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemnetsocketsnetworkstreammemberstopic.htm

    From the example it looks you're using a different way of dealing with TcpListener though, so these may not be helpful. I have no idea beyond that.

    As to why your logging isn't working, why don't you put something in your exception handler to write an event log entry on a catch. Not sure why that's giving you trouble.

    As for Application.StartupPath, it works fine in a service (just tested it). The trick is to add a reference to System.Windows.Forms.dll in the Project menu -> Add Reference...

  9. #9

    Thread Starter
    New Member russgreen's Avatar
    Join Date
    Apr 2003
    Posts
    12
    So is it OK to use Application.Startuppath with a service? I wasn't sure thats all.

    Thanks for all your help

    Russ

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