Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

C#
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.
   }
}
Posted
Updated 20-Dec-16 22:59pm
Comments
Richard MacCutchan 21-Dec-16 4:49am    
That is the wrong way to do it. You should just send the message to the client and then use the receive command to wait for a response. Also your if test is wrong, you need ==.
F-ES Sitecore 21-Dec-16 5:09am    
You need to use what are called reset events, google "c# manualresetevent" for explanations and examples. It's like a sleep in that when the server process hits it will pause execution, but it allows another process (the client code) to trigger the state such that it allows the server event to then continue processing, so it's a sleep that other threads can control.

1 solution

As @Richard MacCutchan already wrote, try this:

C#
//if(i=25) 

if(i == 25)
 
Share this answer
 
Comments
[no name] 21-Dec-16 5:13am    
Or if you wish the compiler to catch the error:
if(25 == i)
Leo Chapiro 21-Dec-16 5:31am    
Right, better!
Member 11543226 22-Dec-16 4:05am    
that is the typing mistake there, but it does not solve my eproblem

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900