I am so confusing about using asynch
with webform
, I make onClick function for button in asp.net server side, and inside this function I make another function this function is asynch
and return type of it Task<int>
, in side this function I put Task.Run
which run some code and I use await with it, after await finishing I want to change label text in my UI but after finish await there is no thing happen in UI
Code of click button:
protected void btn_click(object sender , EventArgs e)
{
fun();
}
Code of asynch function:
public asynch Task<int> fun()
{
Task<String> s = Task.Run(()=>someCodeTakeTime());
await s;
lable.Text = "finish";
return 1;
}
I know it is not recommended to using Task.Run
in side asynch
, and my code not make useful job, but I want to know from it how asynch
function works exactly.