views:

5336

answers:

6

Hi, all.

I'm looking to convert a small .NET console application into a Windows Service. I'd like to build two versions, one using .NET 2.0 and another with .NET 3.5 .

Are there radically different approaches that need to be taken, or will the 2.0 version be roughly equivalent to the 3.5 version? Where's a good source of information (i.e. a web-based guide) that can walk me through the steps of setting up the service?

Thanks! P.A.

+1  A: 

The thing to remember is that .NET 3.5 is a set of additional libraries on top of .NET 2.0, so, unless you are planning on taking advantage of any additional features provided by .NET 3.5 (or .NET 3.0) like LINQ or WCF the code would be identical.

Try looking at the documentation for ServiceBase, which is the base class that you will need to inherit, to get things started.

Scott Dorman
+4  A: 

Actually, .NET 3.5 does change the C# code a little. For example, you can use the var keyword, and you can use the hidden private variables for properties. It is still based on CLR 2.0.

There is a pretty good article at msdn that talks about windows services and walks you through building one.

Loki Stormbringer
It only changes the C# code if you choose to use the new language features. Nothing in the language forces you to do so and you can still write code in the "old .NET 2.0 style" if you want.
Scott Dorman
+1  A: 

This I believe is a decent walk through with screenshots and code samples. I think it may have been what I used for the first windows service I wrote. I think it was written back in .NET 1.1, but should still help walk you through the process. As far as the differences between 2.0 and 3.5, I would say there can/will be as much difference as you want there to be. I don't believe you will be required to change anything, but as other posters have mentioned and as you can find all over SO, there are a lot of new features that can be very beneficial that came with .NET 3.5.

Timothy Carter
+2  A: 

To supplement Rick's answer, I'd suggest the MSDN Walkthrough

It is incredibly verbose and touches on event logging as well as an installer.

MikeHerrera
A: 

I'm curious. Why a console app as a service?

How does it behave if no one is logged on? If several folks are logged on?

And if it's not auto-start, what advantages does it have over a normal exeutable?

cookre
+1  A: 

There is at least one place where service code will need some attention to make it work in .net2/vs2005 vs. .net35/vs2008.

This is especially true if you write your service and installer using in c# 2.0 and compile and deploy using .net35/vs2008, the link below might save you a bit of time:

Custom Actions Changed

Scott