More than one user Service may run within the same process

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

HI

I need some help in writing More than one Service run within the same process

I am writing NT service in C#. And the issue is I am trying to write
multiple services with in the same process. I am reading a config file vale
and looping the values to create services.

For example: Config File Has a Key “ServicesToRun“ And Value is
“SerOne;SerTwo;SerThreeâ€

I want to read the values and create three services. And also install three
services

Service Name should be
SerOne
SerTwo
SerThree

Thanks in advance
NIK
 
Each service would have it's own class derived from ServiceBase, then

ServiceBase.Run ( new ServiceBase[] { SerOne, SerTwo, SerThree } ) ;

But I don't know whether or not the services will run in one process or
three, my guess is three.
 
But I have only one service.cs file. And I want to assign a name to service
and based on the service name I will hit different database to do the work.

Here is the sample I am trying to DO
{
ServicesToRun = new System.ServiceProcess.ServiceBase[] {new XXX() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);

ArrayList x = new ArrayList();

string strValue =
System.Configuration.ConfigurationSettings.AppSettings["ServicesToRun"].ToString();
string[] ArrServisesToRun = strValue.Split(';');

foreach(string ServiceName in ArrServisesToRun)
{
// I am not sure how to take it from here….
x.Add(new System.ServiceProcess.ServiceBase[] {new XXX()})

}
}



Thanks
NIK
 
I'm not quite sure I follow that, it looks strange. How about:

(Given a string listofservices)


string[] x = listofservices.Split ( new char[] {';'} ) ;
ServiceBase[] servicestorun = new ServiceBase [ x.Length ] ;

for ( int i = 0 ; i<x.Length ; i++ )
{
servicestorun [ i ] = new myservice ( x [ i ] ) ;
}

ServiceBase.Run ( servicestorun ) ;

then each instance of myservice gets its marching orders from the parameter
to its constructor.
 
I am not sure I understood correctly your logic. I am trying to give more
information.

I have a service called Datawarehouseservice .cs

And I want to install the separate services for different Reginal databases.
And all it does is the same functionality across the databases.

Instead of writing it as different services for the regions I want to make
it single service.cs file and loop it based on the config file. And

I heard that it is possible in the .net framework. If I fallow the code you
given it needs different service.cs files…..is that correct?

If I want to use only one service.cs file. How do I do it.


Thanks
NIK
 
As I understood it you not only wanted one file, but one class, so my code
showed how to do that. If you want more than one class in the file go ahead
and do so.

Otherwise, I'm not sure what problem you are perceiving.
 
Back
Top