I'm no expert in terms of asychronous operations and hoping that someone can help me point out the problem.
In one of my methods I have written a wrapper,
public static async Task<int> ExecuteNonQueryRawSQLAsync(string sqlStatement)
{
int _returnValue = -1;
using (SqlConnection _conn = new SqlConnection("connectionString"))
{
using (SqlCommand _comm = new SqlCommand())
{
_comm.Connection = _conn;
_comm.CommandText = sqlStatement;
_comm.CommandType = CommandType.Text;
// other codes on setting parameter
try
{
await _conn.OpenAsync();
_returnValue = Convert.ToInt32(await _comm.ExecuteNonQueryAsync());
}
catch (Exception)
{
throw;
}
}
}
return _returnValue;
}
in my UI, I call the method like this,
int _recordsAffected = await MyClass.ExecuteNonQueryRawSQLAsync("INSERT....");
To test if it's really working, i tried to supply an invalid database server address in the connection string so it keeps on searching until it throws an exception.
While the program is still connecting, the UI freezes. What are the things that are missing in my wrapper? or are there any other needed initializations that I need to do?