title: can I stop a task in C# and get a stack trace
body: <p>I've got a base level function in xunit looks sort of like:</p>
  <pre class="lang-cs prettyprint-override"><code>async Task LimitTestTo( Timespan maxTime, Task theTest )
  {
      await Task.WaitAny( theTest, Task.Delay( timespan ));
      if (theTest.IsCompletedSuccessfully) return;
      // ?
      throw Exception(f&quot;Test timed out after {maxTime}&quot;});
  }
  </code></pre>
  <p>And this works fine. However, it just tells me the thing failed - it doesn't tell me why.  What I want is to use debugging sort of functionality where I have a ? to</p>
  <ul>
  <li>if the other task is actually doing something
  <ul>
  <li>figure out what thread it's running on</li>
  <li><em>pause</em> that thread</li>
  <li>get the stack trace</li>
  <li>display it in the test output</li>
  <li><em>terminate</em> that thread</li>
  </ul>
  </li>
  <li>otherwise
  <ul>
  <li>explain why it's not - ie what it's waiting on or whatever</li>
  </ul>
  </li>
  </ul>
  <p>now obviously - cancellationtoken or anything can't work as
  a) I've got no knowledge of or control over the test passed in...
  b) it requires cooperation - by definition this will only ever occur in a time when a programmer has screwed up - it's probably waiting on a lock or something - so relying on the task to be nice and well behaved is pretty pointless.</p>
  <p>I'm playing with dte.debugger.Localprocesses attach, but I'm hoping there's a way to do it from inside the app</p>
  <p><strong>bottom line - what I want to capture is why a test is hanging on the build machine... I couldn't care less if the rest of the program is now in a bad, unknown or corrupted state</strong></p>