Let say i have an application that uses a database. And whenever this application starts it backups the database to some location. And this backup process takes too much time.
To make the gui responsive I would use async await. Like this;
public async Task BackupDataBase(){
using(SqlCommand command = new SqlCommand(@"BACKUP DATABASE [MyDatabase] TO DISK = 'C:\....\MyDatabase.bak'"), connection)
{
await command.ExecuteNonQueryAsync();
}
}
My question is; Can my application use the same connection to query some other things without any need to lock? Or should i lock the connection while asynchronous method is working?