Reputation: 131
In my application, I am using socket while receiving acknowledgment. I have to check my function for certain amount of time (lets say for x no of seconds) for acknowledgment.
if acknowledgment not received then wait for x no. of seconds wait till the given amount of time.
What is the best way to do this?
Upvotes: 0
Views: 79
Reputation: 46
Use Stop Watch to execute a function for a particular time.
//Below code will excecute the code for 10 sec
Stopwatch stopWatch = new Stopwatch();
do
{
stopWatch.Start();
//perform your Function
if (result = true)
{
stopwatch.reset();
break;
}
}While (stopWatch.Elapsed.Seconds <= 10));
Upvotes: 1