Stack Overflow when updating winforms label text

  • Thread starter Thread starter Ethan Strauss
  • Start date Start date
E

Ethan Strauss

Guest
I am getting Stack Overflow errors when I update a Windows Forms Label text property 2652 or 2653 times. I assume the stack has that much room, but what stack is it, and is there a way to reset it?

The calling code looks like so

private void button1_Click(object sender, EventArgs e)
{
Task writePatientsTask = new Task(() => TryToOverflow());
writePatientsTask.ContinueWith(Continuer);
writePatientsTask.Start();
}

private void TryToOverflow()
{
for (int iterations = 0; iterations < 10000; iterations++)
{
UpdateMessage($"Iteration {iterations}");
System.Threading.Thread.Sleep(10);
}
}
private void UpdateMessage(string message)
{
WinTools.SetTextForControl(message, messagesLabel);
}

public static void SetTextForControl(string text, Control control)
{
if (control.InvokeRequired)
{
control.Invoke(new SetTextDelegate(SetTextForControl), text, control);
}
else
{
ToolTip controlTip = new ToolTip();
controlTip.SetToolTip(control, text);
control.Text = text;
}
}


Thanks for any help!

Ethan


Ethan Strauss

Continue reading...
 

Similar threads

Back
Top