Do not conduct a survey. Use the built-in synchronization tools.
RestResponse<T> response = null; var executedCallBack = new AutoResetEvent(false); client.ExecuteAsync(request, (RestResponse<T> aSyncResponse)=>{ response = aSyncResponse; executedCallBack.Set(); }); executedCallBack.WaitOne(); //continue execution synchronously
As a side note, I had to switch the order of operations inside the callback. In your example, there was a race condition, since the flag could allow the main thread to continue and try to read the answer before the callback thread wrote it.
source share