RobinHood70 RobinHood70 - 1 year ago 123
C# Question

Async passthrough methods

When bubbling up asynchrony, given a method whose only purpose is to call another asynchronous method with a specific parameter, which of the follow is the accepted/preferred pattern, and why?

async Task MyMethodAsync() => await MyOtherMethodAsync(1);


Task MyMethodAsync() => MyOtherMethodAsync(1);

Answer Source

I would prefer:

Task MyMethodAsync() => MyOtherMethodAsync(1);

Using async and await actually adds quite a bit of overhead to build a full state machine, where the 2nd is just a simple method call.

The only potential advantage to making the method async itself would be if you wanted to add exception handling, and have the stack trace be the local method, or log the exceptions.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download