469,954 Members | 1,664 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,954 developers. It's quick & easy.

CSharp Windows Service - Interactive

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!
Nov 17 '05 #1
6 6530
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" <js************@logicor.com> wrote in message
news:un**************@TK2MSFTNGP12.phx.gbl...
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!

Nov 17 '05 #2
In message <#q**************@TK2MSFTNGP10.phx.gbl>, "Alvin Bruney [MVP -
ASP.NET]" <www.lulu.com/owc@?.?.invalid> writes
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?

--
Steve Walker
Nov 17 '05 #3
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 [MVP - ASP.NET]" <www.lulu.com/owc> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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" <js************@logicor.com> wrote in message
news:un**************@TK2MSFTNGP12.phx.gbl...
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!


Nov 17 '05 #4
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(ServicesToRu n);
}
}

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
Nov 17 '05 #5
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...
"Doug Forster" <doug_ZAPTHIS_AT_ZAPTHIS_TONIQ_DOT_CO_DOT_NZ> wrote in
message news:%2****************@tk2msftngp13.phx.gbl...
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(ServicesToRu n);
}
}

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

Nov 17 '05 #6
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??

"Doug Forster" <doug_ZAPTHIS_AT_ZAPTHIS_TONIQ_DOT_CO_DOT_NZ> wrote in
message news:%2****************@tk2msftngp13.phx.gbl...
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(ServicesToRu n);
}
}

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

Nov 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Glenn Venzke | last post: by
1 post views Thread by Artur Kowalski | last post: by
13 posts views Thread by NG | last post: by
3 posts views Thread by Lubomir | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.