title: SmartThreadPool - Is it possible to pass delegate method with method parameters?
body: <p>I have a long running process called <code>ImportProductInformation</code> called by a consoleapp that I'm trying to speed up, which appears to be an excellent candidate for thread-pooling, so I did a little searching and came across <a href="http://www.codeproject.com/KB/threads/smartthreadpool.aspx" rel="nofollow">SmartThreadPool</a> on CodeProject and am trying to implement it.</p>
  
  <p><code>ImportProductInformation</code> currently requires an "item", which is just a single entity-framework row pulled from a list.  <code>SmartThreadPool</code> uses a delegate called <code>"WorkItemCallback"</code>, but if I build it like below it complains about "Method name expected" in the foreach loop on <code>smartThreadPool.QueueWorkItem</code>, as it appears I can't pass my params to the delegated method.  What am I missing here?  I'm sure it's something stupid...noob lacking experience with delegates...any help would be appreciated:</p>
  
  <pre><code>    public static void ImportProductInformation_Exec()
      {
          // List
          List&lt;productinformation&gt; _list = GetProductInformation();
  
          // Import
          if (_list != null)
          {
              SmartThreadPool smartThreadPool = new SmartThreadPool();
  
              foreach (var item in _list)
              {
                  smartThreadPool.QueueWorkItem
                    (new WorkItemCallback
                      (ImportProductInformation(item)));
              }
  
              smartThreadPool.WaitForIdle();
              smartThreadPool.Shutdown();
          }
      }
  
      public void ImportProductInformation(productinformation item)
      {
          // Do work associated with "item" here
      }
  </code></pre>
  
  <p>If I change the loop to this I get "Method is used like a Type" in the build error:</p>
  
  <pre><code>            foreach (var item in _list)
              {
                  ImportProductInformation ipi = 
                    new ImportProductInformation(item);
  
                  smartThreadPool.QueueWorkItem(new WorkItemCallback(ipi));
              }
  </code></pre>
  
  <p>Ended up getting it to work with this:</p>
  
  <pre><code>public class ProductInformationTaskInfo
  {
      public productinformation ProductInformation;
  
      public ProductInformationTaskInfo(productinformation pi)
      {
          ProductInformation = pi;
      }
  }
  
  public class PI
  {
      foreach (var item in _list)
      {
          ProductInformationTaskInfo pi = 
            new ProductInformationTaskInfo(item);
          smartThreadPool.QueueWorkItem
            (new WorkItemCallback
              (ImportProductInformation), pi);
      }
  
      public static object ImportProductInformation(Object _pi)
      {
          ProductInformationTaskInfo pi = (ProductInformationTaskInfo)_pi;
          var item = pi.ProductInformation;
  
          // Do work here
      }
  }
  </code></pre>