title: Set thread lifetime at startup
body: <p>Is there a way to set a value for how long a thread should (maximally) be alive when you start the thread? </p>
  
  <p>Said in another way, with "pseudocode", is there anything like this:</p>
  
  <pre><code>Thread t = new Thread();
  t.start();
  t.abort_after_x_seconds(30);
  </code></pre>
  
  <p>which would make the thread abort if it lived more than 30 seconds.</p>
  
  <p>Edit: I still can't get it to work, what I originally had is:</p>
  
  <pre><code>while(true)
  {
      if(...)
      {
          Thread t = new Thread(new ThreadStart(startMethod));
          t.start();
      }
      Thread.sleep(...);
  }
  </code></pre>
  
  <p>the problem is that sometimes the threads will hang (I'm not implementing what the threads do so I don't know exactly why (it's a school project, we're noobs at organizing)), so I want to kill those threads. I tried using Tasks and CancellationTokens as in the examples below, but when the Task hangs
  it can't check if a cancellation request has occured.</p>