2008年5月28日 星期三

C# windows service debuging skill

Recently, I rewrite an active MQ receiver program which is written in Java using Spring Framework. Basically the Java program works very well. However, I thought, reason to rewrite this program is to unify the deployment environment and provide an automatic startup mechanism. Hence, we choose C# Windows Service as our solution to solve the problem in Java.
It is not really painful for us to move the code from Java to C#, however to debug in C# service is really painful.
I found there are three solutions to solve the debug issue:
  1. using the process attach debug method by Visual Studio [1][2]
  2. using #if (DEBUG) #else declarative [3]
  3. Run Windows Service as a console[4]
I chose the third way to debug my program, because, using console mode is most intuited for me and the code is also straightforward.

Reference
  1. Praveen Moosad, Debugging Windows Services in C# and .NET ,http://www.c-sharpcorner.com/UploadFile/prvn_131971/DebuggingWindowsServices02062006014001AM/DebuggingWindowsServices.aspx?ArticleID=f5db56a4-8e1f-4de3-8fe2-1168603450ba, 2006.Arcane Code, Windows Services in C#: Debugging Windows Services (part 4), http://arcanecode.wordpress.com/2007/05/24/windows-services-in-c-debugging-windows-services-part-4/, 2007.
  2. Lee Humphries, Debugging Windows Services under Visual Studio .NET, http://www.codeproject.com/KB/dotnet/DebugWinServices.aspx, 2006.
  3. Einar, Run Windows Service as a console program,http://tech.einaregilsson.com/2007/08/15/run-windows-service-as-a-console-program, 2007.

沒有留言: