title: How do I run a threadpool with parameters, and get to put in a cancellation token as well?
body: <p>I am working on a bit of WPF code for the moment. I am having a problem that I can't find an answer online, so I thought I would ask the StackOverflow community!</p>
  <p>I have a button click event occuring, let's call this:</p>
  <pre><code>  private void CollectData(object sender, RoutedEventArgs e)
      {
          ThreadPool.QueueUserWorkItem(RunLoops, new object[] { 0, 10, 20, 30, 40});
      }
  </code></pre>
  <p>Which works very well and takes this massive task (RunLoops) and puts it on a non-UI thread. However, as I am passing a object with my parameters, I cannot add a CancellationTokenSource to this thread.</p>
  <pre><code> CancellationTokenSource source = new CancellationTokenSource();
  
      private async void CollectData(object sender, RoutedEventArgs e)
      {
          var token = source.Token;
          ThreadPool.QueueUserWorkItem(RunLoops, new object[] { 0,10,20,30,40 }, token);
      }
  </code></pre>
  <p>This gives me an error: no overload method takes 3 arguments. Is there any way around this? As of now, I am trying to include a stop button in my GUI which would just call cts.Cancel(), which is very convenient for the running of this code. Any help would be fantastic.</p>