Geeks With Blogs
.Nettuce Code Salad
    static class Program
    {
        static void Main(string[] args)
        {
            var serviceRunner = new ServiceRunner();
            if (Environment.UserInteractive)
            {
                serviceRunner.Run(args);
                serviceRunner.Stop();
            }
            else
            {
                var servicesToRun = new ServiceBase[] { new Service(serviceRunner) };
                ServiceBase.Run(servicesToRun);
            }
        }
    }
 
    class ServiceRunner
    {
        public void Run(string[] args)
        {
        }
 
        public void Stop()
        {
        }
    }
 
    class Service : ServiceBase
    {
        readonly ServiceRunner serviceRunner;
 
        public Service(ServiceRunner serviceRunner)
        {
            this.serviceRunner = serviceRunner;
        }
 
        protected override void OnStart(string[] args)
        {
          serviceRunner.Run(args);  
        }
 
        protected override void OnStop()
        {
            serviceRunner.Stop();
        }
    }
Posted on Wednesday, May 29, 2013 2:48 PM | Back to top


Comments on this post: Windows Service Template

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Jon Canning | Powered by: GeeksWithBlogs.net