This is my personal blog. The views expressed on these pages are mine alone and not those of my employer.

Tuesday, 19 May 2009

Creating a windows service using the .net framework

Today has been spent attempting to write a windows service in the .NET framework (Using C#). While reasonably hard to get of the ground, after a bit of research they are actually only slighty harder to write than a simple WinForm. I do however want to repeat some bits of my research here, hopefully to make coding a windows service easier in the future:

  • They cannot be simply ran by hitting F5 and hoping for the best. They must be tediously installed (or if like me you can write an External Tool to Visual Studio :-)
  • You need to start the service manually (or again you could write a small batch file [using net start])
  • The service will not be started from a network drive (You will get an error along the lines of: Error 403 File cannot be found) generic huh?

And last but not can't use the Timer control contained in System.Windows.Forms, nope, it has to be a cousin (albeit almost identical) control within the System.Timers namespace. Use of the latter won't cause any compilation problems, it simply won't work, as I eventually found out from this obscure Microsoft article.

As you can see, writing a Windows Service is no trivial task...

Happy coding!

No comments:

Post a Comment