473,396 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 5732
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.