Reputation: 25
I'm using Serenity C# to develop a website.
When I click on a button it should run a SQL command, which starts a stored procedure.
My code
public ListResponse<MyRow> RunSQL(IDbConnection connection, ListRequest request)
{
string sql = "EXEC SP_A @Username='" + Authorization.UserDefinition.Username + "'";
SqlHelper.ExecuteNonQuery(connection, sql);
return new MyRepository().List(connection, request);
}
This code works fine, but it makes my web slow because my web needs to wait for the query to finish.
I want to kick off the SQL command and not wait for the result. Can I use the Task Parallel Library (TPL) for this?
Upvotes: 0
Views: 1249
Reputation: 62157
Can I use TPL (Task Parallel Library)??
No, you can not. You execute ONE statement, I am not even sure where you get the idea that paralellism of one item will do anything. if that query takes a long time, analyze whether it is defective. if it is not defective...
...change the API to be async an return a come back later with a token. It is waiting for the return value because you degiend the API to be synchroneous . you this is not acceptable, then the API is a design error and the design at least of this method should change.
Nothing in async/await/paralellism will change the API design and it will not magically make the request finish faster.
Upvotes: 1