Is it possible to write a .NET service that could also be run as a user
application? This might be something along the lines of defining multiple
entry points, to be used based on how the program is executed.
I would like to do this without creating a DLL for all the program code, and
two executables for the service/application front ends....
Thanks.
--
-Rich 5 1926
Rich,
Seeing as the Windows Service defines a Shared Sub Main in your service
class, you should be able to decide to call the either ServiceBase.Run or
Application.Run to either start the service or display a form.
However I would think a common DLL with two EXE front ends would be a
'cleaner' better encapsulated arrangement.
Hope this helps
Jay
"Rich Bernstein" <ra***@cornell.edu> wrote in message
news:bk**********@news01.cit.cornell.edu... Is it possible to write a .NET service that could also be run as a user application? This might be something along the lines of defining multiple entry points, to be used based on how the program is executed.
I would like to do this without creating a DLL for all the program code,
and two executables for the service/application front ends....
Thanks.
-- -Rich
Doh!
Seeing as this is a C# newsgroup that should be a static void Main.
I was looking at a VB.NET windows service when I wrote it.
Jay
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:uz**************@TK2MSFTNGP11.phx.gbl... Rich, Seeing as the Windows Service defines a Shared Sub Main in your service class, you should be able to decide to call the either ServiceBase.Run or Application.Run to either start the service or display a form.
However I would think a common DLL with two EXE front ends would be a 'cleaner' better encapsulated arrangement.
Hope this helps Jay
"Rich Bernstein" <ra***@cornell.edu> wrote in message news:bk**********@news01.cit.cornell.edu... Is it possible to write a .NET service that could also be run as a user application? This might be something along the lines of defining
multiple entry points, to be used based on how the program is executed.
I would like to do this without creating a DLL for all the program code, and two executables for the service/application front ends....
Thanks.
-- -Rich
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:uz**************@TK2MSFTNGP11.phx.gbl... Rich, Seeing as the Windows Service defines a Shared Sub Main in your service class, you should be able to decide to call the either ServiceBase.Run or Application.Run to either start the service or display a form.
However I would think a common DLL with two EXE front ends would be a 'cleaner' better encapsulated arrangement.
Hope this helps Jay
Yes the hard part is figuring out whether the exe was launched from the
Service Control Manager or by a User. Possible methods include:
- a Command-line switch to run interactivly (easy but inconvienient)
- use win32 API's OpenProcess etc to determine your parent process (hard but
fast)
- use performance counters to determine your parent process (easy but slow)
David
Thanks.....
How do I know within the Main function whether or not it was started as a
service, in order to decide which to way to run it? Unfortunately, if I try
ServiceBase.Run, it gives a Windows Service Start Failure and exits (rather
than throwing an exception).
--
-Rich
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:uz**************@TK2MSFTNGP11.phx.gbl... Rich, Seeing as the Windows Service defines a Shared Sub Main in your service class, you should be able to decide to call the either ServiceBase.Run or Application.Run to either start the service or display a form.
However I would think a common DLL with two EXE front ends would be a 'cleaner' better encapsulated arrangement.
Hope this helps Jay
"Rich Bernstein" <ra***@cornell.edu> wrote in message news:bk**********@news01.cit.cornell.edu... Is it possible to write a .NET service that could also be run as a user application? This might be something along the lines of defining
multiple entry points, to be used based on how the program is executed.
I would like to do this without creating a DLL for all the program code, and two executables for the service/application front ends....
Thanks.
-- -Rich
Rich,
I left that as an exercise for you ;-)
David Browne identified three methods that you can use.
I figured you had an idea of how you knew which way it was started. David's
idea of a command line switch may be the easiest.
Hope this helps
Jay
"Rich Bernstein" <ra***@cornell.edu> wrote in message
news:bk**********@news01.cit.cornell.edu... Thanks.....
How do I know within the Main function whether or not it was started as a service, in order to decide which to way to run it? Unfortunately, if I
try ServiceBase.Run, it gives a Windows Service Start Failure and exits
(rather than throwing an exception).
-- -Rich "Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in
message news:uz**************@TK2MSFTNGP11.phx.gbl... Rich, Seeing as the Windows Service defines a Shared Sub Main in your service class, you should be able to decide to call the either ServiceBase.Run
or Application.Run to either start the service or display a form.
However I would think a common DLL with two EXE front ends would be a 'cleaner' better encapsulated arrangement.
Hope this helps Jay
"Rich Bernstein" <ra***@cornell.edu> wrote in message news:bk**********@news01.cit.cornell.edu... Is it possible to write a .NET service that could also be run as a
user application? This might be something along the lines of defining multiple entry points, to be used based on how the program is executed.
I would like to do this without creating a DLL for all the program
code, and two executables for the service/application front ends....
Thanks.
-- -Rich
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Chris |
last post by:
I built small C# Web and Web Service applications in a
training class last week. The applications worked in the
class, but when I tried to run them again over the
weekend, they both bombed....
|
by: Dao |
last post by:
I have created a windows service called MyService. I followed the MSDN sample code to add the following code but it did not work. What I tried was that to start another or external program when...
|
by: Chris |
last post by:
I posted this in the C# language group, then thought it
might be more appropriate in this group. I would not
cross-post except I want the answer so badly.
I built small C# Web and Web Service...
|
by: kemp100 |
last post by:
guys..i am having a hard time with this one..
i have created a service which works fine..except when i want to
execute another program (notepad.exe)...i know how to execute itusing...
|
by: Ahmed |
last post by:
Hello everyone,
I am designing a chat program for a company. The program will be used
locally(through lan). I am progamming the chat program using VB.NET
windows application. Lets consider the...
|
by: UJ |
last post by:
Is there any way for a windows service to start a windows program ? I have a
service that will need to restart a windows app if it needs to.
TIA - Jeff.
|
by: Joris De Groote |
last post by:
Hi,
I have wrote a program that checks for files and moves these files to the
correct folders when they come in. Everything works fine. However I always
have to start that program manually. I...
|
by: Ed Bitzer |
last post by:
Trying to send groups of email with program using System.Net.Mail. I
do not clear MailMessage but repeatedly loop changing only the Bcc
entries. Works fine if all addresses are valid. As a simple...
|
by: Dean Slindee |
last post by:
Need to write a standalone application that processes data once per day.
Looking for the application program types available that would satisfy these
requirements:
Requirements:
1. Unattended...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |