473,395 Members | 1,581 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,395 software developers and data experts.

service and console app

I'm trying to create a Windows service which can also be run as a
console app if it is started with some switch (eg -console). Is there
any way to do this?
Previously (in VC6) it's just been a matter of using the executable for
my service and run it from the command prompt. What's the equivalent to
this in C#?

TIA,
Håvard

Nov 17 '05 #1
4 3072
I dont think there is one, I guess the usual approach would be to have two
applications (one the service) and a console using remoting to talk to it.

http://www.csharphelp.com/archives2/archive460.html

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

<ho*******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I'm trying to create a Windows service which can also be run as a
console app if it is started with some switch (eg -console). Is there
any way to do this?
Previously (in VC6) it's just been a matter of using the executable for
my service and run it from the command prompt. What's the equivalent to
this in C#?

TIA,
Håvard
Nov 17 '05 #2
Change the static Main method in your service app to something like this:

// The main entry point for the process
// add the string[] args as a parameter
static void Main(string[] args)
{
if ((args.Length > 0) && ("/?" == args[0]))
{
MessageBox.Show("" + "Usage: DELL_QWatcher [/?] [/debug]\n" + "\n" + "/?
Displays this help dialog.\n" + "\n" + "/debug Service as an application
rather", "DELL QWatcher Object");
} else if ((args.Length > 0) && ("/debug" == args[0].ToLower()))
{
// main service object
DELL_QWatcher oWatcher = new DELL_QWatcher();
oWatcher.OnStart(new string[1]);
Application.Run();
oWatcher.OnStop();
} else
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new
DELL_QWatcher() };
System.ServiceProcess.ServiceBase.Run(ServicesToRu n);
}

// this is the normal service code generated by the IDE
// ServiceBase[] ServicesToRun;
// More than one user Service may run within the same process. To add
// another service to this process, change the following line to
// create a second service object. For example,
//
// ServicesToRun = new System.ServiceProcess.ServiceBase[] {new
Service1(), new MySecondUserService()};
//
// ServicesToRun = new ServiceBase[] { new DELL_QWatcher() };

// ServiceBase.Run(ServicesToRun);
}
<ho*******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I'm trying to create a Windows service which can also be run as a
console app if it is started with some switch (eg -console). Is there
any way to do this?
Previously (in VC6) it's just been a matter of using the executable for
my service and run it from the command prompt. What's the equivalent to
this in C#?

TIA,
Håvard
Nov 17 '05 #3
Perfect Microsoft, just what I was looking for!

Thanks a bunch!

Håvard

Nov 17 '05 #4
Actually, I apologize... I don't know why it had Microsoft listed as my
name, perhaps a defualt when I set up this news account... egads, I would
never assume the name of the enemy...

"Håvard Olerud Eriksen" <ho*******@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Perfect Microsoft, just what I was looking for!

Thanks a bunch!

Håvard
Nov 17 '05 #5

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

Similar topics

7
by: Mike | last post by:
I want to create a windows service that will monitor another window service. what i need for the service to do is, if a service is stopped I need it to start the service back up example: ...
9
by: SP | last post by:
Hi All, I wrote a windows service which is supposed to stop after specified amount of time. I am calling OnStop() after specified time. OnStop() methods executed but I dont see the service...
7
by: BW | last post by:
Hi all! I'm not sure where to post this so I'm giving these a try. If there is a better (more appropriate) place to post please let me know. I want to create a service (in C#). The service's...
2
by: Fan Wang | last post by:
Hi All, I wrote a windows service with C# as below. But I can't install it with installutil.exe. I got an error message " Exception occurred while initializing the installation:...
3
by: JohnH | last post by:
Does any one now how to create a .net service thet when run from the command line with say a -D argument will run as a console app and be able to output to that console window. The same .exe would...
12
by: Noam | last post by:
I had originally written a program as a c# console application. The program used a reference that I wrote in c++. Later I was told to re-write the application as a windows service. When the service...
7
by: sunil | last post by:
Hi all, I read an article from http://www.c-sharpcorner.com/Code/2003/Sept/InstallingWinServiceProgrammatically.asp about how to install a windows service programmatically. Based on the code...
11
by: Glenn | last post by:
Hi I've been experimenting with managing state using the Session object. I've created a simple WS with a couple of methods, one which sets a string value, another that retrieves it. Each...
20
by: =?Utf-8?B?cmtibmFpcg==?= | last post by:
I was executing the steps given in http://suppor.microsoft.com/kb/308359 for testing a sample web service application. However, the following line gives a compilation error: localhost.Service1...
0
by: iprogrammer | last post by:
i have a problem when i try to run my windows service ..which is "Error 1053: The service did not respond to the start or control request in a timely fashion" >after this i cannot anything with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
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: 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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.