Code Monkey home page Code Monkey logo

agentfire.lifetime.consoleserviceinstaller's Introduction

Usage:

[RunInstaller(true)]
public sealed class Ins : SmartNetworkServiceInstaller
{
    public Ins() : base("My Test Service", "http://+:80/yay", "https://+:443/yay") { }
}

class Program
{
    static void Main(string[] args)
    {
        using (WinService service = new WinService())
        {
            if (Environment.UserInteractive)
            {
                // Startup as console app.
                Controller.Run(service.ServiceName, new RunParameters(), args != null && args.Length == 1 ? args[0] : null);
            }
            else
            {
                // Startup as service.
                // Use any or your services you want. The args is passed from Windows correctly and can be used.
                ServiceBase.Run(service);
            }
        }
    }
}

Notes:

  1. Make sure your Installer class is located in the Entry Assembly (exe).
  2. Make sure your Installer class has [RunInstaller(true)] attribute.
  3. Make sure your Installer class is not located in some other class, that is, nested.
  4. Use Environment.UserInteractive property to detect whether or not your program is run as service or as desktop-user-started.
  5. using (WinService service = new WinService()) is not necessary. I just like to dispose of things. :)
  6. SmartNetworkServiceInstaller isn't the only thing in there.

Some extra feature:

[RunInstaller(true)]
public sealed partial class ProjectInstaller : SimpleLocalSystemInstaller
{
    public const string ServiceName = "My Test Service";

    public ProjectInstaller() : base(ServiceName) { }

    // Lets your service's startup to depend on some SQL instances already installed in the system.
    protected override IEnumerable<string> EnumerateDependencies()
    {
        return base.EnumerateDependencies().Concat(ServiceHelper.GetInstalledMssqlServerInstances());
    }
}

agentfire.lifetime.consoleserviceinstaller's People

Contributors

agentfire avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.