Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Windows service Error

Windows service Error

Scheduled Pinned Locked Moved Visual Basic
visual-studiohelpquestion
3 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    oakleaf
    wrote on last edited by
    #1

    I have created a windows service (in VB, using VS 2010) and once I have it installed and attempt to run it, I receive the following error in the event viewer:

    Service cannot be started. System.InvalidOperationException: Cannot change service name when the service is running.
    at System.ServiceProcess.ServiceBase.set_ServiceName(String value)
    at PostProcessing.PostProcessing.InitializeComponent()
    at PostProcessing.PostProcessing.OnStart(String[] args)
    at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)

    I have a feeling that this has to do with the installer, but not sure what to check. All of the names are "PostProcessing". Anybody have an idea for me? Thanks.

    D 1 Reply Last reply
    0
    • O oakleaf

      I have created a windows service (in VB, using VS 2010) and once I have it installed and attempt to run it, I receive the following error in the event viewer:

      Service cannot be started. System.InvalidOperationException: Cannot change service name when the service is running.
      at System.ServiceProcess.ServiceBase.set_ServiceName(String value)
      at PostProcessing.PostProcessing.InitializeComponent()
      at PostProcessing.PostProcessing.OnStart(String[] args)
      at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)

      I have a feeling that this has to do with the installer, but not sure what to check. All of the names are "PostProcessing". Anybody have an idea for me? Thanks.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      OK, looking the stack trace, in your OnStart handler, you're calling an InitializeComponent method. You normally don't see that in a service at all, but you do in Windows Forms apps. Makes me wonder what you're doing... From the InitializeComponent method, you're doing something with a ServiceBase object. Perhaps you inherited that in a class of yours?? Perhaps you're setting a Name property somewhere you shouldn't be?? It's easy enough to trace. Put a Thread.Sleep in your OnStart method for, say, 20 seconds. Then set a breakpoint on a line just after the Sleep. Start the service, then go to Visual Studio and in the Debug menu -> Attach to Process... Find your service and attach to it. When you hit the breakpoint, you can step through the code line-by-line and watch what happens.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak

      O 1 Reply Last reply
      0
      • D Dave Kreskowiak

        OK, looking the stack trace, in your OnStart handler, you're calling an InitializeComponent method. You normally don't see that in a service at all, but you do in Windows Forms apps. Makes me wonder what you're doing... From the InitializeComponent method, you're doing something with a ServiceBase object. Perhaps you inherited that in a class of yours?? Perhaps you're setting a Name property somewhere you shouldn't be?? It's easy enough to trace. Put a Thread.Sleep in your OnStart method for, say, 20 seconds. Then set a breakpoint on a line just after the Sleep. Start the service, then go to Visual Studio and in the Debug menu -> Attach to Process... Find your service and attach to it. When you hit the breakpoint, you can step through the code line-by-line and watch what happens.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak

        O Offline
        O Offline
        oakleaf
        wrote on last edited by
        #3

        Your reply made the error make sense. :thumbsup: Esp. the "InitializeComponent" piece. I wanted to use a windows service so that I could use the timer to schedule it rather than schedule a task to run as a user. I have moved the project to a windows form, and will use a service to run the program instead. Most likely what I want to do would not work as a service anyways...
        My objective: Multiple transactions against a remote server, sending and receiving JSON, deserializing the responses and then taking the appropriate actions on a MS SQL server db.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups