It turns out that lately I have been developing a calculator in c# with windows form. Exceptions are checked in the calculator and when one occurs, my idea is to display an error in the textbox and after half a second the text in the textbox is equal to the operator. I was recommended to use Thread.Sleep() but that stops the whole program and the error message is not displayed. The code section:
TextBox.Text = "Error";
Thread.Sleep(500);
operador = save;
operador = operador.Replace("*", "x");
operador = operador.Replace("/", "÷");
TextBox.Text = operador;
TextBox.Focus();
TextBox.SelectionStart = TextBox.Text.Length;
I suggest that you use threads to run in another thread to process the value change of the TextBox, and thus obtain that effect without blocking the entire program.
Here is an example how you could use it:
Shorter solution:
You add async to the method associated with the event that launches the code, and you can now execute the "sleep" (Delay) asynchronously
EDIT: Requires .Net Framework version 4.5 or higher.