I'm trying to display an error on my form and use timer to remove the error in a second. I have:
const string sendingError = "currently sending a message please wait";
System.Timers.Timer timer = new System.Timers.Timer(1000);
commandValues.errorList[sendingError] = sendingError;
commandValues.updateErrorList();
this functions as it should by updating a label with the error message
timer.Elapsed += ((source, e) =>
{
var INDEX = Form.ActiveForm.Controls.IndexOfKey("errorBox");
Debug.WriteLine(Form.ActiveForm.Controls[INDEX]);
Form.ActiveForm.Controls[INDEX].Text = "";
Debug.WriteLine("2" + Form.ActiveForm.Controls[INDEX]);
});
timer.Enabled = true;
timer.Start();
the debug line displays
1System.Windows.Forms.Label, Text: currently sending a message please wait
1System.Windows.Forms.Label, Text: currently sending a message please wait
1System.Windows.Forms.Label, Text: currently sending a message please wait
1System.Windows.Forms.Label, Text: currently sending a message please wait
// etcetera
As you can see, the second debug line is never displaying. Break points agree that it leaves the delegate when I try to change the label.
I'm new to C# so any advice would be appreciated, but specifically I would like to know how to have the main form edited after a timeout and why my attempt is failing.