如何暂停执行for循环直到客户端响应? [英] How to pause execution of for loop until client responces?

查看:102
本文介绍了如何暂停执行for循环直到客户端响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个服务器程序,当有计数器(int)为25时,我想暂停我的for循环执行服务器向客户端询问一个问题你想继续发送数据吗?如果客户端响应是那么我的for循环应该从计数器26恢复。现在我的程序停止在for循环中如果使用thread.sleep(),当客户端响应因为控制在for循环时它不会得到intocase 睡眠方法在这里对我不起作用。

有没有办法在c#中实现这一点。 (VS10)?



我尝试过:



 Case   $

for int i = 1 ; i < = 50 ; i ++)
{
// 将代码置于此处以停止for循环if if(i = 25)nd client with responces then then resume from 26。

if (code [i]!= 0
{
InputSimulator.SimulateTextEntry(code [i]);
}

如果(i = 25
{
// Thread.Sleep(#sec); //这里的时间取决于客户的反应。
}
}

解决方案



for int i = 1 ; i < = 50 ; i ++)
{
// 将代码置于此处以停止循环if(i = 25)nd客户端响应然后恢复从26开始。

if (code [i]!= 0
{
InputSimulator.SimulateTextEntry(code [i]);
}

if (i = 25
{
// Thread.Sleep(#sec); //这里的时间是d依赖于客户响应。
}
}


正如@Richard MacCutchan已经写过的那样,试试这个:



  //   if(i如果(i ==  25 


I am writing a server program in which i want to pause my for loop execution when there is counter(int) is 25 at that time server asks a question to client "do you want to continue sending data?" if client response "yes" then my for loop should resume from counter 26. now my program when stopped in for loop if using "thread.sleep()" , it is not get intocase when the client response becaous control is in for loop so "sleep" method doesnt work for me here.
Is there any possible way to achieve this in c#. (VS10)?

What I have tried:

Case "$" :

for(int i = 1 ; i <= 50 ; i++)
{
// put code here to stop for loop if (i=25) nd client responces then resume from 26.

   if (code[i] != "0")
   {   
     InputSimulator.SimulateTextEntry(code[i]);                                                              
   }
   
   if(i=25) 
   {
     //Thread.Sleep(#sec); // here time is depending on client response.
   }
}

解决方案

" : for(int i = 1 ; i <= 50 ; i++) { // put code here to stop for loop if (i=25) nd client responces then resume from 26. if (code[i] != "0") { InputSimulator.SimulateTextEntry(code[i]); } if(i=25) { //Thread.Sleep(#sec); // here time is depending on client response. } }


As @Richard MacCutchan already wrote, try this:

//if(i=25) 

if(i == 25)


这篇关于如何暂停执行for循环直到客户端响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆