Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Just fire the task without async/await without async/await.

private void InitMethod(ServiceControl serviceControl)
{
 if (serviceControl != null)
 {
 Task.Factory.StartNew(() => serviceControl.Execute());
 }
}

In a proper F&F task all exception handling (including a final catch, logging, notifications) is done by the task itself, so you don't need exception handling that async/await provides.

Make the method name reflect what it does. I wouldn't mind a name like FireAndForgetXyz

Just fire the task without async/await.

private void InitMethod(ServiceControl serviceControl)
{
 if (serviceControl != null)
 {
 Task.Factory.StartNew(() => serviceControl.Execute());
 }
}

In a proper F&F task all exception handling (including a final catch, logging, notifications) is done by the task itself, so you don't need exception handling that async/await provides.

Make the method name reflect what it does. I wouldn't mind a name like FireAndForgetXyz

Just fire the task without async/await.

private void InitMethod(ServiceControl serviceControl)
{
 if (serviceControl != null)
 {
 Task.Factory.StartNew(() => serviceControl.Execute());
 }
}

In a proper F&F task all exception handling (including a final catch, logging, notifications) is done by the task itself, so you don't need exception handling that async/await provides.

Make the method name reflect what it does. I wouldn't mind a name like FireAndForgetXyz

Source Link
Gert Arnold
  • 2.1k
  • 1
  • 17
  • 26

Just fire the task without async/await.

private void InitMethod(ServiceControl serviceControl)
{
 if (serviceControl != null)
 {
 Task.Factory.StartNew(() => serviceControl.Execute());
 }
}

In a proper F&F task all exception handling (including a final catch, logging, notifications) is done by the task itself, so you don't need exception handling that async/await provides.

Make the method name reflect what it does. I wouldn't mind a name like FireAndForgetXyz

lang-cs

AltStyle によって変換されたページ (->オリジナル) /