[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Debug Windows Service

Posted on 2013-06-28
2
Medium Priority
?
413 Views
Last Modified: 2013-06-29
Not that experienced in Windows Services Development

I see at this link that I can I can install the Service locally and then attach to Process in Visual Studio

Is there anything else I should know?

Does it have to be COM Visible or anything else?
0
Comment
Question by:lrbrister
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 23

Accepted Solution

by:
Ioannis Paraskevopoulos earned 2000 total points
ID: 39286554
Hi,

I have recently done some research in windows service development and i have found the following tips very useful.

First of all, you probably have noticed that each time you need to stop start your service, and then attach to the process, and even install it if it is not already installed. I used to do all these steps manually until i found a solution.

In the Visual Studio open your Windows Service project.
Go to the Project Properties
Go to the Build Events tab (I think that the location of that tab depends on the studio version, so feel free to ask. You may need to look for a button in the complie tab)
There you may define PreBuild and PostBuild events.

So in the PreBuild you may write the following:
net stop <service name>
Exit /b 0

Open in new window

This will stop the service if it is running.

Then in the PostBuild screen add the following:
%WinDir%\Microsoft.NET\Framework\v2.0.50727\installutil /u "$(TargetPath)"
%WinDir%\Microsoft.NET\Framework\v2.0.50727\installutil "$(TargetPath)" 
net start <service name>
exit /b 0

Open in new window

This dictates the service to be uninstalled, then install a fresh copy and then start it.
If the service is not installed the first time you build it, it will fail, but just to another build and you are good to go

Another thing you may want to take notice, is the version of the framework. In my example i use .NET 2 installutil, but i think there is one for framework 4, so you might need to change the path.

This is a way for automating some staff you would have to do manually and it all came handy in my case...

So, now, attaching to the process of the service will help you debug a service that is up and running, but it won't help you debug the onstart method. So supposedly you do have code in the OnStart method, you can put the following in its first lines:

#if DEBUG then
     System.Diagnostics.Debugger.Break
#end if

Open in new window


The above code says to the compiler that this will run only if visual studio is set to debug mode (or you run from the debug folder). So, you wan't have to worry if you are in release mode. Then if you ARE in debug mode it will pop up a window asking you if you wish to debug the program and with what tool you want to do this. Just choose a new visual studio instance and happy debugging....

I hope this helps,
Giannis
0
 

Author Closing Comment

by:lrbrister
ID: 39286607
Perfect
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question