Related to this answer,
If I truly do want to "Fire and Forget" a method that does return a task, and (for simplicity) let's assume that the method isn't expected to throw any exceptions. I can use the extension method listed in the answer:
public static void Forget(this Task task)
{
}
Using this approach, if there are bugs in action of the Task
that cause an exception to be thrown then when the unexpected exception is thrown, the exception will be swallowed and go unnoticed.
Question: Wouldn't it be more appropriate in this scenario for the extension method to be of the form:
public static async void Forget(this Task task)
{
await task;
}
So that programming errors throw an exception and get escalated (usually bringing down the process).
In the case of a method with expected (and ignorable) exceptions, the method would need to become more elaborate (as an aside, any suggestions on how to construct a version of this method that would take a list of acceptable and ignorable exception types?)
question from:
https://stackoverflow.com/questions/22864367/fire-and-forget-approach 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…