How can I update the value of a Label control periodically?

前端 未结 4 2006
别跟我提以往
别跟我提以往 2021-01-29 05:53

I\'m trying to make a label display some text, and then after a short while refresh itself and be able to re-display something else later. At the moment however I don\'t know ho

4条回答
  •  北荒
    北荒 (楼主)
    2021-01-29 06:16

    Updated for async/await. This will

    // Update all text with warning message
    foreach (var x in mod)
    {
          labelWARNING.Visible = true;
          labelWarningMessage.Text = "This module has a prerequisite module: " + x;
    }
    
    // Wait 1 second or 1000ms    
    await Task.Delay(1000);
    
    // Now dismiss the message
    foreach (var x in mod)
          labelWarningMessage.Text = "";
    

    The surrounding function needs to be an public async Task SomeMethod() or
    public async void buttonClick(object sender, RoutedEventArgs e)
    to use the await keyword

提交回复
热议问题