I am getting the warning "This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. Although it sounds obvious, I thought I was covered because I run all the processes and have an Await Task.WhenAll() in my processFiles method. Do I need to be doing this a different way? Any thoughts would be kindly appreciated.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace ProcessFiles
{
public partial class ProcessFiles : Form
{
public ProcessFiles(int userLevel, int userID)
{
}
private void btnProcess_Click(object sender, EventArgs e)
{
processFiles();
}
async Task<int> processFiles()
{
var processingTasks = new List<Task>();
foreach (string fileName in listBox1.Items)
{
processingTasks.Add(process012(fileName));
processingTasks.Add(process123(fileName));
processingTasks.Add(process234(fileName));
}
await Task.WhenAll(processingTasks);
return (1);
}
async Task<int> process173(string fileName)
{
return (retVal);
}
async Task<int> process032(string fileName)
{
return (retVal);
}
async Task<int> process018(string fileName)
{
return (retVal);
}
async
keyword but no await. Isn't the message clear? Also, if you want to return a completed task usereturn Task.FromResult
withoutasync
– Panagiotis Kanavosasync
which means they need anawait
. And so doesbtnProcess_Click
– Panagiotis Kanavos