简体   繁体   English

如何在C#中使用ServiceController启动Windows Service的新实例

[英]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.. 我有一个使用Visual Studio安装程序安装程序安装的Windows服务应用程序.Windows服务应用程序正在使用C#套接字程序使用IP和端口号从服务器读取数据并将其连续写入文本文件中.IP地址和端口号从数据库中读取。现在按照我的要求,假设客户端要在此情况下再添加一个服务器ip地址和端口号,如何在Windows服务中创建数据捕获应用程序的新实例。这是我的代码在Windows Service OnStart()方法中。

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. 只需启动另一个线程并将第二个IP和端口作为参数传递给它即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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