private void UpdateLabel(string text) { if (label.InvokeRequired) { label.BeginInvoke((MethodInvoker)delegate () { UpdateLabel(text); }); } else { label.Text = text; } }
private void AnimateLabel(string text) { for (int i = 0; i < text.Length; i++) { label.BeginInvoke((MethodInvoker)delegate () { label.Text = text.Substring(0, i + 1); }); Thread.Sleep(100); } }In this example, the AnimateLabel method uses the BeginInvoke method to update the label's text character by character, with a delay between each update. The System.Windows.Forms namespace is part of the .NET Framework Class Library, included in the System.Windows.Forms.dll assembly.