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

Q: Debugging a Service.

Hi!

To debug a service i usually attach to the service when it is running.

How ever in this case. the service is not starting due to an error when i
initialize the
service, therefor the service is not started and i can not debug it. (Step
thru code)

Can you "pre" attach to the service before the service is running?

Any other tips on how to debug?

I have began to remove code line by code line, but there is a lot of code :)

Regards
Martin
Aug 14 '07 #1
3 1071
On Aug 14, 3:01 pm, "Martin Arvidsson, Visual Systems AB"
<martin.arvids...@vsab.netwrote:
To debug a service i usually attach to the service when it is running.

How ever in this case. the service is not starting due to an error when i
initialize the
service, therefor the service is not started and i can not debug it. (Step
thru code)

Can you "pre" attach to the service before the service is running?

Any other tips on how to debug?

I have began to remove code line by code line, but there is a lot of code :)
The simplest way is often to add a long sleep as the very first line
of code, which allows you to attach the debugger to the process while
it's sleeping.

Jon

Aug 14 '07 #2
well why didn't i think of that :) Because then i wouldnt ask you *lol*

Thanks
Martin

"Jon Skeet [C# MVP]" <sk***@pobox.comskrev i meddelandet
news:11*********************@w3g2000hsg.googlegrou ps.com...
On Aug 14, 3:01 pm, "Martin Arvidsson, Visual Systems AB"
<martin.arvids...@vsab.netwrote:
>To debug a service i usually attach to the service when it is running.

How ever in this case. the service is not starting due to an error when i
initialize the
service, therefor the service is not started and i can not debug it.
(Step
thru code)

Can you "pre" attach to the service before the service is running?

Any other tips on how to debug?

I have began to remove code line by code line, but there is a lot of code
:)

The simplest way is often to add a long sleep as the very first line
of code, which allows you to attach the debugger to the process while
it's sleeping.

Jon

Aug 14 '07 #3
I use the following conditional pattern to debug a Windows Service in C#.
This has the advantage that if you run in debug mode in Visual Studio, the
service never needs to be installed - it is simply run as a "plain old"
executable. No need to attach anything, just set a breakpoint:

#if ( ! DEBUG )

ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] {new TestService()};
ServiceBase.Run(ServicesToRun);

#else

// debug code: allows the process to run as a non-service
// will kick off the service start point, but never kill it
// shut down the debugger to exit

TestService service = new TestService();
service.OnStart(null);
Thread.Sleep(Timeout.Infinite);

#endif
--
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"Martin Arvidsson, Visual Systems AB" wrote:
Hi!

To debug a service i usually attach to the service when it is running.

How ever in this case. the service is not starting due to an error when i
initialize the
service, therefor the service is not started and i can not debug it. (Step
thru code)

Can you "pre" attach to the service before the service is running?

Any other tips on how to debug?

I have began to remove code line by code line, but there is a lot of code :)

Regards
Martin
Aug 14 '07 #4

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

Similar topics

3
by: David Evans | last post by:
Hi I have a service created in VS.NET, which I can install and run quite happily. After teh service is running, I can attach and run the debugger. However, if I set a breakpoint in the IDE the...
6
by: Dmitri Shvetsov | last post by:
Hi All, Did somebody see the situation when the VS refuses to debug the Web Service at all? I can't catch why, the initially created Web Service can be debugged very easy but after some changes...
0
by: ZMan | last post by:
Scenario: This is about debugging server side scripts that make calls to middle-tier business DLLs. The server side scripts are legacy ASP 3.0 pages, and the DLLs are managed DLLs...
16
by: Serdar Kalaycý | last post by:
Hi everybody, My problem seems a bit clichè but I could not work around. Well I read lots of MSDN papers and discussions, but my problem is a bit different from them. When I tried to run the...
5
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As...
3
by: Sathyaish | last post by:
How do you debug a web service in Visual Studio .NET 2003? To give you some background, I have been programming for some over 8 years now and know how to debug VB, VC++ apps in Visual Studio 6.0...
0
by: Ken Allen | last post by:
The MSDN documentation on remote debugging is a bit sparse, to say the least, and there is almost no information available on the 'best' way to configure this. I should note that my development...
4
by: John Wilmot | last post by:
I have a service that is set up to use remoting. Is there a way that calls from a web page to this service can be debugged in Visual Studio 2005?
3
by: Rick | last post by:
We have a web site that was built as an ASP.Net Web Site, I am unable to remote debug, when build ing the web site there is not a dll or PDB file generated. I can debug on my local machine but...
7
by: GaryDean | last post by:
(this was also posted on the MSDN WCF forum but the answers over there are not so good) I have a WCF Library hosted by IIS 6 and it all works fine. However I need to step through the code in the...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.