Results 1 to 6 of 6

Thread: Starting a service from another

  1. #1
    Join Date
    Jan 2010
    Posts
    61

    Starting a service from another

    I am trying to start a service (S2) from another service (S1). So of course I already searched for info on the subject. So far I have tried using a ServiceController component. I specified the name of S2 and the machine on which it is located. So far, nothing works, always get the following error message (in the event log):
    Cannot open S2 service on computer 'themachineinquestion'.
    Are there additional settings required? I coded like this:

    Code:
    For Each sc as ServiceProcess.ServiceController in ServiceProcess.ServiceControl.GetServices("theserver")
         If sc.ServiceName = "VTE" Then
              sc.Start()
         End If
    Next
    But got
    Cannot open VTE service on computer 'theserver'.

  2. #2
    Join Date
    Nov 2008
    Posts
    1,022

    Re: Starting a service from another

    A service does not operate like a normal application. The OnStart has a maximum time limit, after this period if you're not out of the OnStart service, startup failure is considered

    The windows.forms.timer apparently does not operate in a service (there are 2 other types of timer in the framework that must go)

    If not generally in service on a thread that starts a loop (with a .sleep even when) in the OnStart

  3. #3
    Join Date
    Jan 2010
    Posts
    61

    Re: Starting a service from another

    Ok, I understand better now the problem. I did not know the trick of the timeout for the OnStart. But I have another service and that there, sometimes it starts sometimes it refuses. I do not change course, nothing in the OnStart once to another. Is it possible that the same set of instructions executed at different times from one time to another?

    I mean I know it is never exactly the same time that is taken for their implementation but unless you are really at the limit of the timeout, so that it crashes once and not the other.

  4. #4
    Join Date
    Nov 2008
    Posts
    1,022

    Re: Starting a service from another

    In theory its the same time but in practice that's not. By the parallel with a copy of the file on windows explorer, if you copy a file and the copy takes 2 minutes. Now you copy the same file but even though 3 other copies, 1 will not tale 2 minutes but can be 10.

    So it's the same if the processor and other resources are requested execution time is longer

  5. #5
    Join Date
    Jan 2010
    Posts
    61

    Re: Starting a service from another

    Ah yes, very fair for example.

    In case, here is my OnStart procedure:

    Code:
    Protected Overrides Sub OnStart(ByVal args() as String)
        ' Add code here to start your service. This method should set things
        ' in motion so your service can do its work.
        JEvents.WriteEntry("Start Service")
        Timer1.Enabled = True
        Dim sr as New StreamReader(localDir & "ftpserver.txt")
        siege = sr.Readline.split(";")
        ftpServer = sr.Readline.split(";")
        sr.Close()
        sr.Dispose()
    End Sub
    You think I do too many things? I put the instructions that must be initialized at the beginning of the process. They do not change thereafter. Note that I could do at the beginning of the event timer ....

    That saves me from having a restart the service if the content files are required to be changed (change ftp server for example).

    What is the best way forward? For single services training, I followed a tutorial online that explains how to do a service check memory usage.

  6. #6
    Join Date
    Nov 2008
    Posts
    1,022

    Re: Starting a service from another

    A single line in a file that is not long in theory, so you could leave it in the OnStart. But try to catch it is recommended, with registration error in a file or in the newspaper, because if you plant service can not know why else
    and everyone can potentially make bugs

    If you want to deport a thread in that gives:
    Code:
    Protected Overrides Sub OnStart(ByVal args() as String)
        ' Add code here to start your service.  This method should set things
        ' in motion so your service can do its work.
        JEvent.WriteEntry("Start Service")
       dim th as new system.threading.thread(addressof StartAsync)
       th.start
    End Sub
     
    Private Sub StartAsync()
      try
        Timer1.Enabled = True
        Dim sr as New StreamReader(localDir & "ftpserver.txt")
        siege = sr.Readline.split(";")
        ftpServer = sr.Readline.split(";")
        sr.Close()
        sr.Dispose()
      catch ex as exception
        ' registration error
      end try
    End Sub

Similar Threads

  1. Getting error when starting SQL service in Windows 7
    By Gaia in forum Operating Systems
    Replies: 5
    Last Post: 07-01-2011, 07:50 PM
  2. WIA service is hung on starting
    By cherry77 in forum Operating Systems
    Replies: 1
    Last Post: 11-09-2010, 01:33 PM
  3. Windows Search Service Not Starting
    By REDBULL in forum Operating Systems
    Replies: 5
    Last Post: 16-01-2010, 10:37 AM
  4. Vista Audio Service not starting
    By tommiy in forum Operating Systems
    Replies: 1
    Last Post: 12-02-2009, 06:45 PM
  5. WSUS Service not starting Automatically
    By haritable in forum Server Update Service
    Replies: 2
    Last Post: 20-04-2007, 12:30 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,653,421.33886 seconds with 17 queries