c# - Should we provide both asynchronous and synchronous implementations of SmtpClient wrapper? -
c# - Should we provide both asynchronous and synchronous implementations of SmtpClient wrapper? -
according this article, should not provide synchronous wrappers of asynchronous implementations.
we've abstracted system.net.smtpclient behind interface can test code sends emails.
since smtpclient has both asynchronous , synchronous implementations, should expose both of these or expect consumer of our ismtpclient interface wait our asynchronous sendasync method.
not sure guidelines here when comes building general purpose library. in our case know need utilize both async , sync versions.
if consumers need both asynchronous , synchronous versions , can provide you should. don't forcefulness consumers sync on async, hurts performance , end in deadlocks.
you can see many examples of in .net libraries semaphoreslim (wait/waitasync) or tpl dataflow (post/sendasync). when there's async alternative there's sync option. case can recall there's async version in winrt, that's because they discouraging long sync calls.
as ned stoyanov mentioned, toub's article more wrappers, , not true sync/async operations.
c# .net asynchronous task-parallel-library async-await
Comments
Post a Comment