Why does a function not run procedurally? I would expect the following code would first show a TextBox, then idle for 3 seconds, and hide the TextBox, but the application simply sleep for 3 seconds without showing the TextBox
public Main()
{
MyTextBox.Visibility = Visibility.Visible;
Thread.Sleep(3000);
MyTextBox.Visibility = Visibility.Hidden;
}
[EDIT 1]
I can't really find an explanation as to why the thread did not sleep AFTER the textbox goes visible. Thread.Sleep should not start until the previous line MyTextBox.Visibility finished running. Hence, my question: why aren't the statement not run procedurally/sequentially?
[EDIT 2]
I can understand the downvotes but yet I could not find an explanation from "duplicate" questions. The UI thread should render my TextBox.Visibility before Thread.Sleep(3000), but that's not the case.
My original thought of how the UI thread should go:
Main() -> Initialize UI Controls -> Run Constructor -> Set TextBox.Visibilily Property (Visible) -> Render TextBox visible on GUI -> Thread.Sleep(3000) -> Set TextBox.Visibility Property (hidden) -> Render TextBox hidden on GUI
But in practice, the thread looks more like the following:
Main() -> Initialize UI Control -> Run Constructor -> Set TextBox.Visibilily Property (Visible) -> Set TextBox.Visibilily Property (Hidden) -> Thread.Sleep(3000) -> Render TextBox visible on GUI -> render TextBox hidden on GUI