title: Using TPL in IIS 7 - Disposing Tasks/Threads/Requests
body: <p>Forgive the title, I am not quite sure how to word what I am looking for, or if I even know what I am looking for.</p>
  
  <p>I have a service that is running that takes a potentially large amount of requests concurrently. Additionally, within the service, I must make a certain amount (usually 10-15) requests to external services, which I am running in parallel.This code looks like the following</p>
  
  <pre><code>        Task&lt;IResponse&gt;[] tasks = new Task&lt;IResponse&gt;[Adapters.Count];
          for(int i = 0; i &lt; Adapters.Count;i++)
          {
              IAdapter adapter = Adapters[i];
  
              Func&lt;IResponse&gt; makeExternalHttpRequest= () =&gt; adapter.MakeExternalHttpRequest(element, mappings);
              tasks[i] = Task.Factory.StartNew&lt;IResponse&gt;(() =&gt;
                  {
                      try
                      {
                          var result = makeExternalHttpRequest();
                          if (!token.IsCancellationRequested)
                          {
                              return result;
                          }
                      }catch(Exception exception)
                      {
  
                      }
  
                      return null;
  
                  }, token);
          };
          var timeout = ...some timeout value
          Task.WaitAll(tasks,timeout, token);
          tokenSource.Cancel();
  
          for (int i = 0; i &lt; tasks.Length; i++)
          {
              if (tasks[i].Result != null)
              {
                  if (tasks[i].IsCompleted)
                  {
                      results.Add(tasks[i].Result);
                  }
              }
          }
  </code></pre>
  
  <p>Everything seems to be working as I expected for the past 6-7 months, and then yesterday, the server went down and I was sent the following from our system admin.</p>
  
  <p><img src="https://i.stack.imgur.com/l9LRo.png" alt="enter image description here"></p>
  
  <p>If you notice the highlighted area, it is quite large for the time elapsed.</p>
  
  <p>I am guessing this contributed to why the server went down, but we are still looking into what happened.</p>
  
  <p>Any idea on what is going on, and what my next steps should be?</p>