CSharp Windows Service - Interactive

M

Microsoft

I'm new to CSharp, previously having done all my development in Delphi. I
need to create a service, and for the development cycle I wish it to be an
interactive service and use message boxes to show various messages. I know
I can set the interactive property via the SMC, but I would rather set it
programmatically so I do not have to get in and out of the SMC each and
every time. Is this even possible?

Thanx!
 
A

Alvin Bruney [MVP - ASP.NET]

possible, but troublesome. services don't normally have a gui. Why do you
need that sort of functionality? Have you thought of a console app instead?

--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc
 
S

Steve Walker

"Alvin Bruney [MVP - said:
possible, but troublesome. services don't normally have a gui. Why do you
need that sort of functionality? Have you thought of a console app instead?

Write as a class library, debug from a console app, implement from a
service?
 
M

Microsoft

The service won't have a GUI, the message box solution is strictly during
development to assist in debugging. When the actual service goes into
production, it will not interact with the desktop. I know all kinds of
people claim to make your service a class and use it via a console app or
other regular app, which seems like an awful lot of extra work to do a
simple basic service... And it may be appropriate, but being new to CSharp,
I wouldn't know how to begin to build sucha a beast that runs in a colnsole
or regular app, then extract the parts for a service...


Alvin Bruney said:
possible, but troublesome. services don't normally have a gui. Why do you
need that sort of functionality? Have you thought of a console app
instead?

--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc
Microsoft said:
I'm new to CSharp, previously having done all my development in Delphi.
I need to create a service, and for the development cycle I wish it to be
an interactive service and use message boxes to show various messages. I
know I can set the interactive property via the SMC, but I would rather
set it programmatically so I do not have to get in and out of the SMC
each and every time. Is this even possible?

Thanx!
 
D

Doug Forster

Here is a cut'n'paste of a reply I wrote to someone a while back:

Here is a code snippet showing how we do it:

static void Main(string[] args) {

// if there is one command line switch and that switch is "/?" then
we'll
// show some help.

// if there is one command line switch and that switch is "/a" then
we'll
// start as an application rather than a service.

if ((args.Length > 0) && ("/?" == args[0])) {
MessageBox.Show("" +
"Usage: HOObjectService [/?] [/a]\n" +
"\n" +
"/? Displays this help dialog.\n" +
"\n" +
"/a Starts the Head office object service as an application rather
" +
"than a service.", "Head office object service");
} else if ((args.Length > 0) && ("/a" == args[0].ToLower())) {
CHOObjectService hoserve = new CHOObjectService();
hoserve.OnStart(new string[1]);
Application.Run();
hoserve.OnStop();
} else {
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new
CHOObjectService() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
}

You can then just set up a command line switch in the debugger setup so you
can just 'run' the service from the IDE but when installed as a service it
works as a service.

Cheers

Doug Forster
 
M

Microsoft

Thanx, I'll put this in place when I get to the office tomorrow... I do this
same type of thing in my Delphi services, and it usually works like a
champ... Not being familiar with CSharp, I wasn't sure how to accomplish
the same thing...
 
M

Microsoft

OK, I did give this a try by copying and pasting this code to my Main() in
my current service app. But it's telling me the namespace for args and
Application don't exist. What am I supposed to add a reference too in order
to get this to wortk??
 

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