The text "lblDate.Content" disappears when I use the sleep timer to close the window. How do I get that text to display? The rest of the window/text is shown. I'm open to other ways to autoclose a window.
public void DisplayErrorMessage(string message)
{
// Error Message TextBox
textBox1.Text = message;
Show();
// Show date and logged message
lblDate.Content = "This error has been logged and an administrator contacted: " + DateTime.Now;
// Auto close window
System.Threading.Thread.Sleep(3000);
this.Close();
}
Sleep is not a timer. It is a command to tell the thread to stop processing (blocks the thread) for an amount of time. In this case you are blocking the application thread. If your intention is to keep the window open for 3 seconds before closing it you should may want to check out the Timer class.
Perhaps Application.DoEvents()
to update the drawing of your controls could help?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With