Your post makes not much sense.
If you want to fire-and-forget an async method, then just calling it directly is enough.
public Task RunAsync() { }
public Constructor()
{
RunAsync(); // fire-and-forget by not awaiting and ignoring returned task
}
There is no need to use Task.Run
or Command
, which technically does nothing on top of running the method.
But this kind of fire-and-forget code is frowned upon, because it makes testing of the code difficult. And starting such code in constructor makes the object creation have unexpected side-effects that are not immediately obvious. It is recommended to have some kind of Initialize
method that can be called.
Another issue is that if the method causes an exception, a special handler must be register, otherwise it crashes whole application.