简体   繁体   中英

How to start a new instance of Windows Service using ServiceController in C#

I have a Windows Service Application which i have installed using Visual Studio Setup Installer.The Windows Service Application is using C# Socket Program to read data from server using Ip and Port number and write it into the text file continuously.The ip address and port number is read from the database.Now as per my requirement,Suppose the Client wants to add one more server ip address and port number in this case how can i create a new instance of the data capture application in windows service.. Here is my code in Windows Service OnStart() method..

protected override void OnStart(string[] args)
    {
        _thread = new Thread(DoWork);
        _thread.Start();

    }

no you dont need to restart the service..

protected override void OnStart(string[] args)
{
    _thread1 = new Thread(DoWork);
    _thread1.Start();
    _thread2 = new Thread(DoWork);
    _thread2.Start();
}

Pass some parameters to both the threads and then work accordingly

you dont need to create a second instance of service for that. just start another thread and pass it the second IP and port as parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM