title: Async & Tasks - Searching through a list of websites
body: <p>I'm trying to create a class that can search a string in a list of websites in an asynchronous way.</p>
  
  <p>The following code is working, but I'm getting a feeling that it's done totally wrong:</p>
  
  <pre><code> public static class Searcher
      {
  
          public struct SearchResult
          {
              public SearchResult(string Url, bool Found)
              {
                  this.Url = Url;
                  this.Found = Found;
              }             
  
              public string Url;
              public bool Found;
          }
  
          public async static Task&lt;SearchResult&gt; SearchWebsiteAsync(string url, string str)
          {
              HttpClient client = new HttpClient();
              var urlContents = await client.GetStringAsync(url);
  
              System.Console.WriteLine("Found string in website {0}", url);
              bool foundString = (urlContents.Contains(str) ? true : false);
  
              return new SearchResult(url, foundString);
          }
  
          public static async Task&lt;IEnumerable&lt;SearchResult&gt;&gt; StartSearch(string str)
          {
              List&lt;SearchResult&gt; results = new List&lt;SearchResult&gt;();
              List&lt;Task&lt;SearchResult&gt;&gt; taskList = new List&lt;Task&lt;SearchResult&gt;&gt;();
  
              foreach (var url in TheWeb.URLs)
              {
                  System.Console.WriteLine("Searching URL {0}", url);
  
                  var t = new Task&lt;Task&lt;SearchResult&gt;&gt;(() =&gt; SearchWebsiteAsync(url, str));
                  t.Start();
                  taskList.Add(t.Result);
              }
              //Task.WaitAll(tasks.ToArray());
  
              foreach (var task in taskList) {
                  results.Add(task.Result);
              }            
  
              return results;
          }
      }
  </code></pre>
  
  <p>Especially that I have <code>Task</code>'s inside <code>Task</code>'s : <code>var t = new Task&lt;Task&lt;SearchResult&gt;&gt;(() =&gt; SearchWebsiteAsync(url, str));</code></p>
  
  <p>Is there are a better way (if possible without <code>Parallel</code> because I'm still trying to get some understanding of async-await and tasks)</p>