Asynchronous task and close sql connection
Will this CommitAsync method execute synchronously in the Commit method?


I wouldn't phrase it that way, CommitAsync always executes asynchronously, but Commit wait for it to complete synchronously.


  Is it best practive to pass new CancellationToken() in the Commit method?


It's better to use CancellationToken.None, to make the meaning clearer. Though functionally, the two are equivalent.


  Will the base.SaveChangesAsync() call in CommitAsync() close the connection if it was opened beforehand?


I don't think it will, a single connection can be used for multiple commands.

In general, you should create a new connection for each separate operation (which may comprise more than one command) you do and then dispose the connection, which closes it. This won't hurt efficiency, because connections are actually pooled, so closing the connection object means that the actual connection can be reused by another operation.



var status = new ContextStatus();

var task = Task.Run(async () =&gt; { status = await CommitAsync(userName, new CancellationToken()); });
task.Wait();

return status;


This is unnecessarily verbose and complicated. Instead, I would write it like this:

return Task.Run(() =&gt; CommitAsync(userName, new CancellationToken())).Result;


CommitAsync returns Task&lt;ContextStatus&gt;, so Task.Run() will also return that type. The Task's Result will give you the ContextStatus, synchronously waiting for the Task to complete before returning.



SqlParameter param = new SqlParameter()


Why not use var here too? The type of the variable is clear, so specifying the type just makes the code more verbose.