title: How can I use Activator.CreateInstance to instantiate a generic type as part of a using block?
body: <p>What I'd like to achieve is to convert the following method to something more generic:</p>
  
  <pre><code>    private Task&lt;TestResult&gt; SpecificServiceWarmUp(string serviceEndPoint)
      {
          return Task&lt;TestResult&gt;.Factory.StartNew(() =&gt;
          {
  
              using (var service = new MySpecificClient(serviceEndPoint))
              {
                  // do some stuff with specific client
              }
          });
      }
  </code></pre>
  
  <p>A more generic version would look like:</p>
  
  <pre><code>    private Task&lt;TestResult&gt; GenericServiceWarmUp&lt;TService&gt;(string serviceEndPoint)
      {
          return Task&lt;TestResult&gt;.Factory.StartNew(() =&gt;
          {
  
              using (/* instance of TService */)
              {
                  // do some stuff with generic client
              }
          });
      }
  </code></pre>
  
  <p>What I don't know is how to tell the <code>using</code> block to use <code>Activator</code> to create the instance of the generic type. Is this possible? If so, how can I do this?</p>