1
I would like to create a Windows service monitoring and I want to register a customizable amount of services. For this I need to have a Servicecontroller array dynamically, the problem is that of Exception when I try to assign the service name to the Servicename property.
Follow an example below:
//Eu declaro uma variável global
ServiceController[] scService;
//Aqui vai o código que busca os serviços e põe em um Array de String
//aí o contaService tem a quantidade de serviços cadastrados
scService = new ServiceController[contaService];
//Agora quando vou dar o nome aos servicos
for (int i = 0; i < contaService; i++)
{
//Nessa linha da exception
scService[i].ServiceName = scNome[i];
}
And what’s the mistake?
– Jéf Bueno
Looking at the code is probably Null Excption error, probably forgot to assign or instantiate scService.
– Dev
Yes, it is Nullreferenceexception
– Ro_GEEK
@Ro_geek put an answer right below, try to use in your code.
– Dev