I have made a simple example that returns the data from a database table.
private Task<DataSet> GetDataAsync(string connStr)
{
return Task.Run(() =>
{
DataSet ds = new DataSet();
using (SqlConnection conn = new SqlConnection(connStr))
{
conn.Open();
using(SqlCommand cmd = new SqlCommand("SELECT * FROM TABLE", conn))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(ds);
}
}
}
return ds;
});
}
What would have been the difference if a had marked the method as async and instead of return Task.Run I would have used return await Task.Run?