Yes, you can do the same thing in C#, but that is a very bad idea.
This way of making a pause is called a busy loop, because it will make the main thread use as much CPU as possible.
What you want to do instead is to set up a timer, and call a callback method from the tick event:
public void Wait(double seconds, Action action) {
Timer timer = new Timer();
timer.Interval = (int)(seconds * 1000.0);
timer.Tick += (s, o) => {
timer.Enabled = false;
timer.Dispose();
action();
};
timer.Enabled = true;
}
Usage example:
textbox.text = "Test";
Wait(5.0, () => {
textbox.text = "Finish";
});
7
solved Delay in c# not thread.sleep [closed]