[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.remoting

Debugging .NET Service process

Bob Rundle

7/8/2004 7:39:00 PM

There doesn't seem to be a newsgroup for .NET windows services, so I'll ask
this question here...

I want to create a debug version of my windows service so which is not
derived from System.ServiceProcess.ServiceBase. I want to do this so I can
easily debug the process.

At the present moment I have a lot of #if DEBUG/#endif sections in the main
service process to accomplish this. My question is: Is there a more
elegent way to do this?

Bob Rundle


5 Answers

Sunny

7/8/2004 7:59:00 PM

0

What I would do is to put all my functionality in a separate class, and
to use OnStart just create an object from that class and pass the
execution into it.

Then, my class will implement an event DebugMessage.

That way, I can easily create a console app, in which Main method I''ll
create the object (like in the service), and hook an event handler in
which I''ll record the output.

And whenever you need to write something, you just invoke the event.

So, if the event is captured, there will be output, otherwise, not.

Or, you can take a look at this article in MSDN:
ms-
help://MS.VSCC.2003/MS.MSDNQTR.2004JAN.1033/vbcon/html/vbtskaddingtraces
tatementstoapplicationcode.htm

And take a look at Debug class. It''s methods are invoked only if the
this is a debug compilation, so in release there will be no output.

Sunny


In article <uwaa$MSZEHA.3132@TK2MSFTNGP10.phx.gbl>, rundle@rundle.com
says...
> There doesn''t seem to be a newsgroup for .NET windows services, so I''ll ask
> this question here...
>
> I want to create a debug version of my windows service so which is not
> derived from System.ServiceProcess.ServiceBase. I want to do this so I can
> easily debug the process.
>
> At the present moment I have a lot of #if DEBUG/#endif sections in the main
> service process to accomplish this. My question is: Is there a more
> elegent way to do this?
>
> Bob Rundle
>
>
>

Bob Rundle

7/8/2004 8:13:00 PM

0

Sunny,

Thanks...I know all about the Debug class.

Nothing replaces the debugger however and the ability to single step and
examine variables. Programmers complain that windows services are hard to
debug, but with a few #if/#endif you suddenly have an orginary windows app
that is easy to deal with. I don''t understand why people don''t approach
services this way, at least in development.

Your idea to create a separate console app for debug is a good one, except
that it would mean creating yet another VS.NET solution and I have more than
enough of these already.

So I will stick to my #if/#endif code. It works but it is ugggglay!

Regards,
Bob Rundle

"Sunny" <sunny@newsgroups.nospam> wrote in message
news:e2g1SYSZEHA.3844@TK2MSFTNGP10.phx.gbl...
> What I would do is to put all my functionality in a separate class, and
> to use OnStart just create an object from that class and pass the
> execution into it.
>
> Then, my class will implement an event DebugMessage.
>
> That way, I can easily create a console app, in which Main method I''ll
> create the object (like in the service), and hook an event handler in
> which I''ll record the output.
>
> And whenever you need to write something, you just invoke the event.
>
> So, if the event is captured, there will be output, otherwise, not.
>
> Or, you can take a look at this article in MSDN:
> ms-
> help://MS.VSCC.2003/MS.MSDNQTR.2004JAN.1033/vbcon/html/vbtskaddingtraces
> tatementstoapplicationcode.htm
>
> And take a look at Debug class. It''s methods are invoked only if the
> this is a debug compilation, so in release there will be no output.
>
> Sunny
>
>
> In article <uwaa$MSZEHA.3132@TK2MSFTNGP10.phx.gbl>, rundle@rundle.com
> says...
> > There doesn''t seem to be a newsgroup for .NET windows services, so I''ll
ask
> > this question here...
> >
> > I want to create a debug version of my windows service so which is not
> > derived from System.ServiceProcess.ServiceBase. I want to do this so I
can
> > easily debug the process.
> >
> > At the present moment I have a lot of #if DEBUG/#endif sections in the
main
> > service process to accomplish this. My question is: Is there a more
> > elegent way to do this?
> >
> > Bob Rundle
> >
> >
> >


Sunny

7/8/2004 10:18:00 PM

0

Hi Bob,

In article <#qMICgSZEHA.1652@TK2MSFTNGP09.phx.gbl>, rundle@rundle.com
says...
> Your idea to create a separate console app for debug is a good one, except
> that it would mean creating yet another VS.NET solution and I have more than
> enough of these already.
>
> So I will stick to my #if/#endif code. It works but it is ugggglay!
>

You don''t have to. Create a new project in the existing solution as
console app. Do not make it default. And run it with
rightclick/debug/start new instance. And make reference from it to the
main assembly with your class.

I do it for all my services that way. It is really easiest way to debug
everything while developing. And when my class is ready and functional,
I just put it in a service.

Sunny

Doug Forster

7/9/2004 1:09:00 AM

0

Hi Bob,

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

"Bob Rundle" <rundle@rundle.com> wrote in message
news:uwaa$MSZEHA.3132@TK2MSFTNGP10.phx.gbl...
> There doesn''t seem to be a newsgroup for .NET windows services, so I''ll
> ask
> this question here...
>
> I want to create a debug version of my windows service so which is not
> derived from System.ServiceProcess.ServiceBase. I want to do this so I
> can
> easily debug the process.
>
> At the present moment I have a lot of #if DEBUG/#endif sections in the
> main
> service process to accomplish this. My question is: Is there a more
> elegent way to do this?
>
> Bob Rundle
>
>


Bob Rundle

7/9/2004 9:03:00 PM

0

I think this is a great idea. I''ll implement it when I get tired of looking
at my #if/#endif logic (Real soon now). This approach is a bit of a
departure from the wizard generated code, but so be it. The more code the
wizard writes for me, the lazier I get.

Regards,
Bob Rundle

"Doug Forster" <doug at _ZAPTHIS_
toniq_ZAPTHIS_DOT_ZAPTHIS_co_ZAPTHIS_DOTnz> wrote in message
news:OGrrNFVZEHA.212@TK2MSFTNGP11.phx.gbl...
> Hi Bob,
>
> 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
>
> "Bob Rundle" <rundle@rundle.com> wrote in message
> news:uwaa$MSZEHA.3132@TK2MSFTNGP10.phx.gbl...
> > There doesn''t seem to be a newsgroup for .NET windows services, so I''ll
> > ask
> > this question here...
> >
> > I want to create a debug version of my windows service so which is not
> > derived from System.ServiceProcess.ServiceBase. I want to do this so I
> > can
> > easily debug the process.
> >
> > At the present moment I have a lot of #if DEBUG/#endif sections in the
> > main
> > service process to accomplish this. My question is: Is there a more
> > elegent way to do this?
> >
> > Bob Rundle
> >
> >
>
>