Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6530661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:46:58+00:00 2026-05-25T09:46:58+00:00

When you create a Windows Service, you create a list of the services you

  • 0

When you create a Windows Service, you create a list of the services you want to start. The default is this:

ServicesToRun = New System.ServiceProcess.ServiceBase() {New Service}

Can you have multiple instances of the same Service class (that bind to different addresses or ports), like this?

ServicesToRun = New System.ServiceProcess.ServiceBase() {New Service("Option1"), New Service("Option2")}

Or will that cause problems? Should we use two different classes instead? What’s the best approach to this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:46:59+00:00Added an answer on May 25, 2026 at 9:46 am

    A service by itself doesn’t bind to addresses or ports. You can make the service start threads or tasks that do, so one service could start threads for listening to e.g. http and other addresses:ports or whatever you want it to do.

    The following example shows you what I mean, it’s in C# but if it doesn’t translate well to you then use this to translate. My Main function would in your case be the Start function of your service.

    public abstract class ServiceModuleBase
    {
        public abstract void Run();
    }
    
    public class SomeServiceModule : ServiceModuleBase
    {
       //Implement Run for doing some work, binding to addresses, etc.
    }
    
    public class Program
    {
    
        public static void Main(string[] args)
        {
    
            var modules = new List<ServiceModule> {new SomeServiceModule(), new SomeOtherServiceModule()};
    
            var tasks = from mod in modules
                        select Task.Factory.StartNew(mod.Run, TaskCreationOptions.LongRunning);
    
            Task.WaitAll(tasks.ToArray());
    
    
            Console.Out.WriteLine("All done");
            Console.ReadKey();
    
    
        } 
    }
    

    Also, here is a nice summary of why your first approach doesn’t work and an alternative way of how to get around that

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create windows service which recieves via some queue tasks to run
i'm starting in Windows Azure. I tried to create a new service namespace following
I want to create windows service for existing in Sun Glassfish v2 server.
i'd like to create a windows service that would be accessible via WCF from
On other windows operating systems, I could create a Windows Service that listens to
To get windows service named MyTestService I create an instance of Win32_Service object then
I'm using WiX 3.5 to create an installer that installs a Windows Service and
I have two windows application, one is a windows service which create EventWaitHandle and
Scenario I've created a windows service, but whenever I start it, it stops immediately.
Installed SlikSvn on Window 2008 server Created Repository at c:\dia\svn\repos running this windows service

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.