Disable debugger evaluation of ValueTask<T>.Result (#25727)
authorStephen Toub <stoub@microsoft.com>
Tue, 16 Jul 2019 19:28:53 +0000 (15:28 -0400)
committerGitHub <noreply@github.com>
Tue, 16 Jul 2019 19:28:53 +0000 (15:28 -0400)
commit7f713f7067ffb6adaa1549f626f6bd04128f0de6
tree684bbccabe853958f6f06b62324e62863995dd23
parent7f1dd83ddb159e2469b85145f228fa60ab3682e2
Disable debugger evaluation of ValueTask<T>.Result (#25727)

If the debugger evaluates a `ValueTask<T>`'s `Result`, that counts as the "you should only consume a `ValueTask<T>`" once, and ends up breaking / hanging / throwing exceptions and other bad stuff while stepping through code in the debugger.

This commit addresses that in two ways:
1. Adds `[DebuggerBrowsable(Never)]` to `Result` to prevent it from showing up in debugger views.
2. Adds a NotifyOfCrossThreadDependency call to its ToString.  This prevents the debugger from using ToString to show an implicit representation of the instance, and it forces the developer explicitly trying to access ToString (e.g. in the watch window) to click a button acknowleding the impact.

(Post 3.0, we should consider removing the `ValueTask<T>.ToString()` override altogether.)
src/System.Private.CoreLib/shared/System/Threading/Tasks/ValueTask.cs