Sonar/FxCop are telling us that we shouldn't use void async methods. That's ok. This is the current implementation:
private async void InitMethod(ServiceControl serviceControl)
{
if (serviceControl != null)
{
await Task.Factory.StartNew(() => serviceControl.Execute());
}
}
// fire and forget ... calling from a non-async method!
InitMethod(serviceControl);
Is this a good way or how would you refactor this method?
private async Task InitMethod(ServiceControl serviceControl)
{
if (serviceControl != null)
{
await Task.Factory.StartNew(() => serviceControl.Execute());
}
}
// fire and forget ... calling from a non-async method!
// when calling without Start then VS is complaining about "not awaiting" this method
InitMethod(serviceControl).Start();