I'm starting to research async and wait for keywords from C # 5.0, so I did some tests using winforms, but now I'm stuck in a situation:
My task is to start the request from the database, and until the request is complete, I want to show the gif for upload in the form.
This is the method that queries the database:
public static async Task<List<string>> GetItensFromDatabase()
{
List<string> names = new List<string>();
using (ServerConn)
{
ServerConn.Open();
SqlCommand cmd = new SqlCommand("Select * From Names", ServerConn);
var ds = new DataSet();
var adapter = new SqlDataAdapter(cmd);
adapter.Fill(ds);
foreach (DataRow dr in ds.Tables[0].Rows)
{
names.Add(dr["Name"].ToString());
}
}
return names;
}
And I call this method here:
private async void button1_Click(object sender, EventArgs e)
{
List<string> itens = null;
itens = await AsyncMethods.GetItensFromDatabase();
ShowItensInListView(itens);
}
Now I have a ubiquitous downloadable gif image on a form that rotates until the GetItensFromDatabase method is called, when the method is launched, the gif stops and when the method finishes running the gif again.
So, is there a way to keep the gif rotating when the GetItensFromDatabase method is run?