472,962 Members | 2,364 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,962 software developers and data experts.

1 executable, multiple services?

Hi!

I know how easy it is to create an NT services using .net framework
(using Visual Studio 2003).

Here is my problem.

I came across a situation where I would like to run 2 instances of a
service executable. From what I have seen the Service name has to be
specified as a "Name" property for the service.

Here is the gist of what I would like to do:
I have an executable which runs as a windows service.
This program connects to a database every 5 min. reads data, creates a
file.

Now, a need came up which I would like to connect to another database.

Database information is in configuration file so pointing to different
database consists of stopping the service, change the config file and
re-start the service.

However, now, I want to run the program to do the same thing on 2
different database simultaneously.

Even if I put 2 copies of executables in different directory, I can not
create 2 different instance of the same service using installTools
since the name of the service is embedded in the program itself (isn't
it??)

What would be the best way of doing this without keeping 2 different
version of the program?

Thanks.

Harry Park.

Jul 11 '06 #1
3 5695
hp*********@yahoo.com wrote:
Here is the gist of what I would like to do:
I have an executable which runs as a windows service.
This program connects to a database every 5 min. reads data, creates a
file.

Now, a need came up which I would like to connect to another database.
Is the functionality for the second database the same? Does it use the
same queries, tables etc. on the other database?
Database information is in configuration file so pointing to different
database consists of stopping the service, change the config file and
re-start the service.

However, now, I want to run the program to do the same thing on 2
different database simultaneously.
Well, the service app can read a config file, and then kick off one or
more threads in separate .dll's if need be to launch two processes at
the same time.
What would be the best way of doing this without keeping 2 different
version of the program?
A service application can have more than one service. When you create
a Service application in .Net, in the designer generated code, it has
these lines (or similar):

ServicesToRun = New System.ServiceProcess.ServiceBase() {New
ServiceClass1}
System.ServiceProcess.ServiceBase.Run(ServicesToRu n)

So the ServicesToRun array only has a single entry (ServiceClass1). If
you add an additional class to your project that inherits ServiceBase,
you can add as many individual services to the app as you need:

The code below would start three services (ServiceClass1,
ServiceClass2, ServiceClass3)

ServicesToRun = New System.ServiceProcess.ServiceBase() {New
ServiceClass1, New ServiceClass2, New ServiceClass3}
System.ServiceProcess.ServiceBase.Run(ServicesToRu n)
Hope this helps a little.

Jul 11 '06 #2
Write a business class that does the work and host it in a service. This way
you can host it in as many different services as you need to.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

What You Seek Is What You Get.
<hp*********@yahoo.comwrote in message
news:11*********************@75g2000cwc.googlegrou ps.com...
Hi!

I know how easy it is to create an NT services using .net framework
(using Visual Studio 2003).

Here is my problem.

I came across a situation where I would like to run 2 instances of a
service executable. From what I have seen the Service name has to be
specified as a "Name" property for the service.

Here is the gist of what I would like to do:
I have an executable which runs as a windows service.
This program connects to a database every 5 min. reads data, creates a
file.

Now, a need came up which I would like to connect to another database.

Database information is in configuration file so pointing to different
database consists of stopping the service, change the config file and
re-start the service.

However, now, I want to run the program to do the same thing on 2
different database simultaneously.

Even if I put 2 copies of executables in different directory, I can not
create 2 different instance of the same service using installTools
since the name of the service is embedded in the program itself (isn't
it??)

What would be the best way of doing this without keeping 2 different
version of the program?

Thanks.

Harry Park.

Jul 11 '06 #3

Chris Dunaway wrote:
hp*********@yahoo.com wrote:
Here is the gist of what I would like to do:
I have an executable which runs as a windows service.
This program connects to a database every 5 min. reads data, creates a
file.

Now, a need came up which I would like to connect to another database.

Is the functionality for the second database the same? Does it use the
same queries, tables etc. on the other database?
Other than Database/Server name everything else is EXACTLY the same.
(Table name, query, functionality, etc..)
That is why I was wondering. we COULD just install this service in
another server with different database connection configuration, but
since the process is rather LIGHT, we were hoping to be able to just
install 2 instances of same executable in one box.
>
Database information is in configuration file so pointing to different
database consists of stopping the service, change the config file and
re-start the service.

However, now, I want to run the program to do the same thing on 2
different database simultaneously.

Well, the service app can read a config file, and then kick off one or
more threads in separate .dll's if need be to launch two processes at
the same time.
We would do this IF functionality is different (hack, we would just
create another service). However, in this case, other than
Database/server name, everything else is identical in terms of
functionality.
What would be the best way of doing this without keeping 2 different
version of the program?

A service application can have more than one service. When you create
a Service application in .Net, in the designer generated code, it has
these lines (or similar):

ServicesToRun = New System.ServiceProcess.ServiceBase() {New
ServiceClass1}
System.ServiceProcess.ServiceBase.Run(ServicesToRu n)

So the ServicesToRun array only has a single entry (ServiceClass1). If
you add an additional class to your project that inherits ServiceBase,
you can add as many individual services to the app as you need:

The code below would start three services (ServiceClass1,
ServiceClass2, ServiceClass3)

ServicesToRun = New System.ServiceProcess.ServiceBase() {New
ServiceClass1, New ServiceClass2, New ServiceClass3}
System.ServiceProcess.ServiceBase.Run(ServicesToRu n)
Hope this helps a little.
Above is a good thought, but still requires un-necessary code changes
(in my opinion) since all I was hoping to do was:
Service A: Runs C:\InstanceA\A.EXE using A.Config in the same directory
Service B: Runs C:\InstanceB\A.EXE using A.Config in the same directory
Where A.EXE in those 2 different directory are EXACTLY the same code.

Another acceptable way would be:
Service A: Runs C:\InstanceA\A.EXE /UseConfigA
Service B: Runs C:\InstanceA\A.EXE /UseConfigB

Is it possible?

Jul 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jay Haslup | last post by:
I am trying to figure out how to get the CMD (dos) window to come up when I call a executable. I have this working on a Win2000/apache machine and am trying to use the same code on a identical...
1
by: Harald Schneider | last post by:
Hi, is there a possibility how to determine a services executable file name (and path) from within the service itself ? I need to create multiple services of the same application. The app...
0
by: Fernando Nasser | last post by:
Multiple database services and multiple versions on Red Hat Linux systems The way it works is that we require a specific service script for each database service (that is listening on each port)....
11
by: Mike | last post by:
Looking to find any information on how to properly configure multiple instances of DB2. This is on Win2k db2 ver 7.2. I am basically looking for information on how the multiple instance settings...
3
by: Dakkar | last post by:
Is that possible to link my program to an executable for example when i close my program the executable that i linked will be closed too How can i do that Posted Via Usenet.com Premium...
14
by: libs | last post by:
I have A.exe that should catch the return code of B.exe (both are written in VB.net) so A.exe can continue processing other commands. but A.exe cannot catch B's return code so an exception is not...
3
by: Matt D | last post by:
I've got two web services that use the same data types and that clients will have to consume. I read the msdn article on sharing types...
0
by: Peter Theill | last post by:
I have these two web services: namespace WebService1 { public class Service1 : System.Web.Services.WebService { public Service1() { } public string HelloWorld() {
2
by: mudge | last post by:
Hi, I'm getting some very strange problems with some C# code. We're running an ASP.NET application on a local server in a DMZ. If I access it using the internal address, the application works...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.