If the value you expect is set somewhere in another application, you can use the wait descriptor:
AutoResetEvent waitHandle = new AutoResetEvent(); ... //thread will sleep here until waitHandle.Set is called waitHandle.WaitOne(); ... //this is where the value is set someVar = someValue; waitHandle.Set();
(note that WaitOne and Set must occur in separate threads, since WaitOne blocks the thread on which it is called)
If you donβt have access to code that changes the value, the best way to do it, as others say, is to use a loop to check if the value has changed and use Thread.Sleep () so that you donβt use as much processor time:
while(!valueIsSet) { Thread.Sleep(100); }
Phil lamb
source share