Hi.
i am using async / await in a form with a datagridview.
The dataGridView1_CellDoubleClick load the GUI correctly,
Wisej.Web.Application.Update(this, async () =>
{
this.ShowLoader = true;
await findCL(txtCL.Text);
this.ShowLoader = false;
});
the same does not happen with the tool linked to a textbox:
private async void txtCL_ToolClick(object sender, ToolClickEventArgs e)
{
if (e.Tool.Name==”TROVA”)
{
Wisej.Web.Application.Update(this, async () =>
{
this.ShowLoader = true;
await findCL(txtCL.Text);
this.ShowLoader = false;
});
}
}
in this second case the Loader remains visible until (for example) I click on the form bar in order to refresh the display.
The findCL method contains another “await” lo load data from Database.
I noticed that by commenting on that part, the interface seems to update correctly.
Is there any reason why it works in one event and not in the other?
Thank you.
Now it’s ok, but a similar situation with textbox textchanged event
private async void textBoxNumero_TextChanged_1(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxNumero.Text)) { resetUI(false); }
else
{
string s = textBoxNumero.Text;
this.ShowLoader = true;
await findOrd(s, getRicType());
this.ShowLoader = false;
Wisej.Web.Application.Update(this); // update the client
}
}
seems not to update the UI. It is updated only if I move the form or click on it.
What is the best way to do a database search while writing text, without using autocomplete?
When using async/await, the C# compiler adds a return statement and “extracts” all the following code into a new callback function. So when you have an “await” it’s like having a “return” statement.
Which means that the request coming from the browser receives a response, and the rest of the code will run “out-of-bounds”, basically without a corresponding request, so it’s unable to update the client unless you call Application.Update() to push the update (works only with WebSocket), or use the automatic polling, or something is requested by the browser.
In your case:
private async void button1_Click(...) { this.ShowLoader = true; await Task.Delay(3000); // simulate async call // the client is update automatically since the request ends here. this.ShowLoader = false; Application.Update(this); // update the client }
Please login first to submit.