Install windows service

I created the Windows service in ASP.NET 4.0, and I use the following command to install the service after running the command line as an administrator:

C: \ Windows \ system32> sc create EnviroTracker1 binpath = "D: \ Freelance Work \ SuperExpert \ gitEnviroTrack \ EnviroTrack \ EnviroTrackerService \ Bin \ Release \ EnviroTrackService.exe"

[SC] CreateService amplification

After that, I go to admin tools -> services and try to start the service, but I get the following error:

---------------------------

Services

---------------------------

Windows failed to start the EnviroTracker1 service on the local computer.

Error 1053: the service did not respond to a start or control request in a timely manner.

---------------------------

OK

---------------------------

installutil. , , . , .

.

+3
4

, ServiceBase OnStart OnStop. , " ", , installutil .

public class YourService : ServiceBase
{
  public static void Main(string[] args)
  {
    ServiceBase.Run(new ServiceBase[] { new YourService() });
  }

  protected overrides void OnStart(string[] args)
  {
    // Add code to start your logic here. Try to return immediately.
  }

  protected overrides void OnStop()
  {
    // Add code to stop your logic here.
  }
}

, OnStart . , , . , , , - .

+1

: , Thread.Sleep OnStart, 100 , .

sc stop EnviroTracker1, . . sc delete EnviroTracker1


http://support.microsoft.com/kb/839174

1053 , 30 OnStart. . OnStart, 2 . , OnStart . , , OnStart .

, . -, . . , . , . , , .

Infact . , , OnStart 30 , , .

, OnStart... , :)

+2

Windows, LINK .

0

, , OnStart Windows, , , .

     protected override void OnStart(string[] args)
     {
        if (args.Contains("DEBUG_SERVICE))
            DebugMode();


         #if DEBUG
             DebugMode();
         #endif



        }

    private static void DebugMode()
    {

        Debugger.Break();
    }

Brian Gideon also makes a good conclusion about the need to "deploy a new thread or otherwise somehow start his logic asynchronously." If you are not responding to a system event or are not listening on a network port, use a timer to do this. My answer contains a sample that I use as a template.

0
source

All Articles