You must Sign In to post a response.
  • Category: .NET

    How to pause execution of for loop until client responces?

    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 in if using "thread.sleep()" , it is not get intocase when the client responce 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)?
  • #768573
    Hi,

    Instead of sleep we have await task which will make your program wait until you get the proper input or response.

    You can create like below,

    for(condn)
    {
    if (Condn == Ok)
    {
    condn++
    }
    else
    {
    await Task.WhenAny(Task.Delay(Expected Condn));
    }
    }



    I have just given the skeleton type of code for your requirement, let us know you are able to understand.
    If you want to perform some operation once the some event is fired we can also perform that.
    Suppose you want to start the process once the button is clicked.



    await Task.WhenAny(Task.Delay(Condn), button.WhenClicked());


    So button clicked event pause will go off and job start running.

    Thanks,
    Mani

  • #768602
    await not present in vs2010 . is there any other option because when promt is in for loop it does not receive new data sent by client


Sign In to post your comments