C# in Async Task change Label Text

前端 未结 5 748
清酒与你
清酒与你 2021-01-03 09:50

The following Code does not change the Text and stops executing the Task

private void button1_Click(object sender, EventArgs e)
    {
        label1.Text = \         


        
5条回答
  •  萌比男神i
    2021-01-03 10:51

    Task.Run is used to envelope an Action (that is not async) into a Task. Any Task that you want to execute should be awaited. Thus, that Task.Run of yours is rigorously doing nothing.

    Mark that button1_Click event handler of yours as async. Then remove that Task.Run and instead do await MyAsyncMethod().

提交回复
热议问题