C# mass build windows services
I basically want to build 10 copies of a windows service that was coded. The only change I want to make to the code is to change开发者_JAVA技巧 the service name from MyService1 to Myservice2 ect...
Is there a simple way to simply build those and export them to twenty different directories?
A simple solution to your problem, as noted in the comments, would be to use multiple threads to spin off the same logic in parallel with one another. There are many ways to achieve this, through background workers, thread pools, and simple one-off threads. For instance, you could have the following setup:
... [In your main thread]
for(int i=0;i<10;i++)
{
new Thread(()=> { DoSomething(); });
// Once spun off, the application will not block here. It will continue
// the next iteration, while DoSomething does something.
}
...
private void DoSomething()
{
// Execute some logic
}
This would spin off 10 threads with your applications logic, executing DoSomething()
. They would all run parallel to each other. However, this is by no means the only way to do it, and in this example, you aren't managing the threads. You're simply instantiating them and forgetting about them. It would really benefit you to read up on threading -- as this would solve your multiple-project issues.
As suggested by others, there are probably better ways to address the problem.
( What is the problem you are solving? )
As for creating multiple services with different names, have you considered the sc
command?
This gets run from the commandline as:
sc create MyService1 binPath= c:\foo.exe
sc create MyService2 binPath= c:\foo.exe
精彩评论