service and console app

H

hoeriksen

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
 
J

John Timney \(ASP.NET MVP\)

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

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
 
M

Microsoft

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(ServicesToRun);
}

// 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);
}
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
 
?

=?iso-8859-1?q?H=E5vard_Olerud_Eriksen?=

Perfect Microsoft, just what I was looking for!

Thanks a bunch!

Håvard
 
J

JSheble

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...

Perfect Microsoft, just what I was looking for!

Thanks a bunch!

Håvard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top