Is there a `when()` statement or some equivalent in C#?

  • A+
Category:Languages

Is there maybe something like a "when" statement in C#?

The reason I want this is because an if statement only checks once if a certain property is true at a particular time, but I want it to wait until the property is true.

Anybody know something I can do in C# that would be similar to a "when" statement?


What you want is SpinWait

e.g. SpinWait.SpinUntil(() => condition);

It will sit there until it either times out (with your specified timeout) or the condition is met.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: