title: Async tasks and data collections using Task.Run without waiting
body: <p>In a WCF service I am dispatching multiple requests to other API/Libraries and I wanted to not wait for these tasks to complete, so I ended up using Task.Run to complete asynchronous tasks <em>without waiting for completion</em>.</p>
  
  <p>The code looks like this:</p>
  
  <pre><code>var someList = new List&lt;int&gt;();                
  var i = 0;
  foreach (var item in group)
  {
       i++;
       var variableOne = i;
       Task.Run(async () =&gt;
       {
                // Does the **variableOne** and variable **i** equals the latest value assigned to it, or the value at the time of calling?**
                // Can someList be prematurely garbage collected before the tasks run, because the original function containing all the code shown in the example has completed (since Task.Run is not awaited)?
                await OcrUtility.ApiOcrUpload(
                new OcrUtility.ApiOcrUploadContract()
                {
                    documentList = item.Documents
                });
        });
  }
  </code></pre>
  
  <p>My three questions are:</p>
  
  <ol>
  <li>Can someList (or any other object referenced by the Task content) be prematurely disposed/garbage collected before the tasks content run?</li>
  <li>Does the variable <strong>i</strong> inside the task equals the latest value assigned to it, or the value at the time of calling?</li>
  <li>I'm used to Javascript, and I know that if I do use <code>setTimeout()</code> in javascript I need to use some kind of <strong>context-copy</strong> trick in order to keep the current value of <code>variableOne</code> at the time of calling, so it does not get set as the latest value assigned to <code>variableOne</code> when the "task" (function in the case of JS) is being executed.
  Do we need to do that kind of copy with C# or does it come with built-in context-copy? Does .Net evaluates which variables are being used, and create a copy of them at the time of calling?</li>
  </ol>