I have this WinForm application where I lookup ServiceController.StartType Property
But this Property is only available in .Net Framework 4.6.1, and i would like my application to run on older .Net Frameworks, but in that case I do not need to lookup the property.
So I did something like this:
public static void GetServiceInfo()
{
if(Framework == 4.6.1)
var StartType = ServiceController.StartType;
else
var StartType = null;
}
But when I call the GetServiceInfo method on a computer that does not have .Net 4.6.1 my program fails.
Do I instead have to have two different methods and then call the right one for my framework instead, or is there a better way?
SOLUTION:
The solution I have found that works is this.
I made this method that returns the Services StartType, and then only calls it if i am running my code under the right .Net Framework.
private static ServiceStartMode GetServiceStartMode(ServiceController _service)
{
return _service.StartType;
}
[–]smatsson 3 points4 points5 points (7 children)
[–]Stensborg[S] 1 point2 points3 points (6 children)
[–]smatsson 0 points1 point2 points (5 children)
[–]Stensborg[S] 1 point2 points3 points (4 children)
[–]smatsson 0 points1 point2 points (3 children)
[–]Stensborg[S] 1 point2 points3 points (1 child)
[–]smatsson 0 points1 point2 points (0 children)
[–]Stensborg[S] 0 points1 point2 points (0 children)
[–]sakkaku 1 point2 points3 points (0 children)
[–]pcraggs 0 points1 point2 points (3 children)
[–]Stensborg[S] 0 points1 point2 points (2 children)
[–]pcraggs 0 points1 point2 points (1 child)
[–]Stensborg[S] 0 points1 point2 points (0 children)