C#:在Do中添加if-else - While条件

时间:2014-09-30 13:31:23

标签: c#-4.0 do-while

如何在do while语句中添加if-else条件。如果“responseStatus”为true,我想等待120secs,否则不要做do-while,继续下一个语句。

            bool responseStatus;

            do
            {
               //Do Something

               responseStatus = IsWaitingForStatus();

            } while (if(responseStatus) ? Thread.Sleep(120): do nothing)

1 个答案:

答案 0 :(得分:1)

它不是很清楚你想要什么,但听起来你想这样做:

bool responseStatus;

// The first call should wait for a specified timeout
do
{
   responseStatus = IsWaitingForStatus();
   if(responseStatus)
       Thread.Sleep(120)
   else
       break;

} while (true);