Tuesday, January 16, 2024

Windows Services: Fix Online Documentation ServiceController

The following links related to the ServiceController class's documentation were likely written prior to 2002 (.NET 1.0 was released in January 2002) and the code samples in the documentation contain some C# examples that are functionally correct but are not written using best practices with respect to C# coding:

The following code was found in the above links where the code demarcated in boldface is not written using best practices:

The Status property above is used in the Console.WriteLine is an enumeration, ServiceControllerStatus, and there is no need to specify ToString().

The Equal method is used above to compare the Status property with a ServiceControllerService value. Best practice would be to use operator==.

The same code as above is show below without the superfluous ToString and using operator== instead other Equals method:



The above change was approved January 16, 2024 and merged into the main documentation branch:




No comments :

Post a Comment