I'm writing an HTTP server. There are many like it, but this one is mine. It contains the following code:
private async void Listen(object state)
{
while (webListener.IsListening)
{
HttpListenerContext context = await webListener.GetContextAsync();
Task.Factory.StartNew(() => ProcessRequest(context));
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
}
The code seems to work like a charm. It feels fast, responsive, does not appear to leak resources, etc. However, the line that I have underlined gives a warning in Visual Studio:
Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
Obviously, the warning goes away if I stick await
in front of the Task.Factory.Startnew()
... but does it really make sense to do that in this situation? I want the ProcessRequest
to be a "fire and forget" operation, I don't care about any return value, I just want to get back to listening for new requests as quickly as possible.
Should I ignore the warning, or am I missing something?