title: Not all code paths return a value in lambda expression of type 'System.Func<int>'
body: <p>I'm creating a task of calling a function CountPixels as shown below</p>
  
  <pre><code>Task&lt;int&gt; task1 = new Task&lt;int&gt;(()=&gt;{CountPixels(croppedBitmap, Color.FromArgb(255, 255, 255, 255));});
  </code></pre>
  
  <p>The code for CountPixels is as follows:</p>
  
  <pre><code>private int CountPixels(Bitmap croppedBitmap, Color target_color)
      {
          int height = croppedBitmap.Height;
          int width = croppedBitmap.Width;
          int matches = 0;
          List&lt;int&gt; x1range = new List&lt;int&gt;();
          List&lt;int&gt; y1range = new List&lt;int&gt;();
          for (int y1 = 0; y1 &lt; height; y1++)
          {
              for (int x1 = 0; x1 &lt; width; x1++)
              {
                  if (croppedBitmap.GetPixel(x1, y1) == target_color
                  {
                      matches++;
                      x1range.Add(x1);
                      y1range.Add(y1);
                  }
              }
          }
          Console.WriteLine("before modification : {0} ms", sw.ElapsedMilliseconds);
          x1range.sort;
          y1range.sort;
          int x1max, y1max;
          x1max = x1range.Count - 1;
          y1max = y1range.Count - 1;
          try
          {
              fruit1.Text = "X1 MIN =  " + x1range[0] + "  X1 MAX =  " + x1range[x1max] + "  Y1 MIN =  " + y1range[0] + "  Y1 MAX =  " + y1range[y1max];
          }
          catch (Exception ex)
          {
              MessageBox.Show("" + ex);
          }
          return matches;
      }
  </code></pre>
  
  <p>I'm getting an Error at the task1 line:</p>
  
  <blockquote>
    <p>Not all code paths return a value in lambda expression of type 'System.Func int>'</p>
  </blockquote>
  
  <p>Please help me out..where am I going wrong?
  Thank you!</p>