c# - How to avoid code duplication when writing DoStuff() and DoStuffAsync() method variants? -


i find need write lot of code synchronous , asynchronous method implementations when writing library functions. there way avoid without overhead? example implement async version , wrap in such way executes synchronously on current thread.

i have an article on subject.

my favorite approach - if sync , async both required - boolean argument hack. is, "core" method takes bool sync argument, , if it's true, guarantees returns already-completed task.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -