Folks, I have an existing library with lots of traditional non-async
methods in it, and I want to provide async versions of the old methods.
Would you consider this to be a simple and trustworthy way of getting this
done?
public Thing GetThing(int key)
{
// This is the existing method
return ...
}
public Task<Thing> GetThingAsync(int key)
{
return Task.Run(() =>
{
return GetThing(key);
}
}
So I just make matching pairs where the old methods are just wrapped in
Task.Run(...). It seems too easy. This is Framework 4.5, and I have a vague
recall that Task.Run doesn't work this easily in 4.0 and it's a bit more
verbose.
*Greg K*