Cannot implicitly convert type 'int' to '...Tasks<int>'

c#, task

Solution

Well, you could return a completed Task:

return Task.FromResult(count);

http://msdn.microsoft.com/en-us/library/hh194922.aspx

Why you'd want to return a Task is a bit of a mystery though. Conceptually, a Task represents a promise that something will happen at some time in the future. In your case, it's already happened, so using a Task is completely pointless.

Problem

if this is async, it'll return with no error, why is it throwing an error without being async, async is worthless in this operation. ``` public Task<int> countUp() { string compare = txtTag.Text; int count = 0; for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (compare == dataGridView1[0, i].Value.ToString()) { BeginInvoke(new Action(() => { count++; txtCount.Text = count.ToString(); })); } } return count; } ```

Original source

Related problems