In the course of writing C# code utilizing the new (for 4.5.1) Task-based asynchronous programming, I’ve run across a couple of places where the await
keyword either is not allowed (a catch block or a property accessor) or the async
keyword greatly complicates the syntax (lambda expressions). I’ve found myself writing this method for two different projects, and so I thought I would drop this Q&D, more-comments-than-code utility method here for others to use if you see the need.
(UPDATE: This works well in console applications; it can cause deadlocks in desktop and web apps. Test before you rely on it.)
1 | /// <summary> |
And, in places where you can’t do something like this…
1 | /// <summary> |
…you can instead do this in that “DependentEntity” property…
1 | /// <summary> |