Visual Studio will warn if you don't use the Task object returned from the function, either immediately with an await
statement or by storing it anin a variable. The reason is that this is the only connection you have with the Task that you have started, and without it there is no way to find out if it has completed or to get the return value.
Stylistically, methodOne
is not a good name for that variable, something like handler
or callback
would make more sense. It also might make sense for the signature to be a little more complex, like accepting a dictionary of parameters and returning an object to serialize to the response.
The other thing to realize is that the called function doesn't know what you do or don't do with the Task, so its behavior can't depend on that. Therefore "using async and having it run on the main thread" does not accurately describe what happens in your situation. The task is run asynchronously on a background task either way, but in your case the main thread does not block on its completion. If you step in with a debugger, you'll see that the code up to the first await (in the while loop) is executed on the calling thread, and at that point control returns to the caller, who could then maintain a reference to the Task if it wants.
As for whether async and Task are right for your job: it sounds like your needs are pretty modest and that there isn't a real argument to be made for or against. If there aren't many requests coming in, it doesn't really matter how you handle them. If there could be a lot coming in and you wanted to limit the impact on the rest of the system, maybe it would make sense to do the work synchronously on a single thread (that you create for that specific purpose).