title: Reading files asynchronously
body: <p>I have this code here for reading files:</p>
  
  <pre><code>private void ReadFile()
  {
      using (StreamReader reader = File.OpenText("data.txt"))
          {
              while ((currentline = reader.ReadLine()) != null)
              {
                  currentline = currentline.ToLower();
                  currentline = RemoveChars(currentline);
                  currentline = RemoveShortWord(currentline);
                  AddWords(currentline);
              }
          }
      }
  </code></pre>
  
  <p>I would like to read files asynchronous for large files but not sure how to do it here. Could you point in the right directions.</p>
  
  <p>This is what I tried to make it asynchronous:</p>
  
  <pre><code>    private async void ReadFile()
      {
  
          using (StreamReader reader = File.OpenText("dickens.txt"))
          {
              while ((currentline =  await reader.ReadLineAsync()) != null)
              {
                  currentline = currentline.ToLower();
                  currentline = RemoveChars(currentline);
                  currentline = RemoveShortWord(currentline);
                  AddWords(currentline);
              }
          }
      }
  </code></pre>
  
  <p>It seem that my <code>AddWords</code> method is not working (when using asynchronous). This method adds words to a dictionary:</p>
  
  <pre><code>    private void AddWords(string line)
      {
          string[] word = line.Split(' ');
  
          foreach (string str in word)
          {
              if (str.Length &gt;= 3)
              {
                  if (dictionary.ContainsKey(str))
                  {
                      dictionary[str]++;
                  }
                  else
                  {
                      dictionary[str] = 1;
                  }
  
              }
          }
      }
  </code></pre>