I want to make his method an Asynchronous Task

Ronald Rex 1,666 Reputation points
2023-11-06T22:27:04.18+00:00

I am new to Asynchronous Tasks. I want to make the below method an Asynchronous Task. Thanks !!!

public static List<PersonModel> LoadPeople()
{
    using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
    {
        var output = cnn.Query<PersonModel>("Select * from Person", new DynamicParameters());
        return output.ToList(); 
    }   
}
Developer technologies | C#
{count} votes

Accepted answer
  1. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2023-11-07T01:20:39.7433333+00:00

    Try the following assuming this is Dapper. I removed the parameter part as you have no parameters in this case.

    Note that the caller will have to use await on the method below.

    Also, check out the following class for more on Dapper and this article.

    public static Task<List<PersonModel>> LoadPeople()
    {
        using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
        {
            return (List<PersonModel>)await cnn.QueryAsync<PersonModel>("Select * from Person");
        }   
    }
    
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.