ArcaneTrain
ArcaneTrain

Reputation: 13

Is there a way to add a delay within an if statement in C#?

I'm trying to have an if statement set a variable to true, then set it to false shortly after. Is this possible, and what is the best way to do this? Thanks for any and all help!

Upvotes: 0

Views: 326

Answers (1)

Ronak Agrawal
Ronak Agrawal

Reputation: 1066

using System.Threading;
Thread.Sleep(1); # will add asleep of 1ms -> 1 mili-sec

EDIT:

Do note that this is in no way hinting to use the specified delay. Nor is it suggesting to use static sleep. That generally always slows down the application. Second to what @Marc suggested.

You would want to evolve your solutioning to event-based structure going forward.

Upvotes: 2

Related Questions