Here's a really late reply to a really old thread re making a library async
by simply wrapping "plain" calls with Task.Run. Yes, Richter describes
nicely how you shouldn't block in worker threads doing I/O as you "pollute
the pool".
The trouble is, sometimes you don't know what a library is doing down the
call stack. I dredged out my old (now defunct) library and realised it's
calling library methods which in turn make web calls to cloud providers
(Rackspace, Azure, etc). I just happen to know that's happening further
down, but what if I didn't?! There is danger that you may write ugly or
inefficient software because you don't know what's happening all down the
line. I suppose this is always a danger when calling "black box" libraries,
unless they're well documented or carefully written. Even now I'm not sure
if my old code like this pollutes the pool:
return Task.Run(() =>
{
return GetSomething(args); // This makes a REST call at the lowest level
}
Someone might be blocking down the stack, I can't tell.
*Greg*