Link to home
Start Free TrialLog in
Avatar of diberi
diberi

asked on

C# Run time limit for function

Hi guys....

I have a question about:
"In my application I have a function to get time from NTP server....
I would like to break this function if after 5 seconds is not possible get the time from web."

Thanks
Avatar of PeteEngineer
PeteEngineer
Flag of India image

what do u mean by :



I would like to break this function if after 5 seconds is not possible get the time from web."
(1) In your executing function, first get the current time of the server & store it in DateTime type variable with addition of 5 seconds.
(2) Then run a loop for comparing current time with the time already saved. And if time limit (in seconds ) exceed the stored value break the function.
ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of XMarshall10
XMarshall10

You can access Win32 (using PInvoke) and then use CreateTimer API to create a timer for 5 secs, and check if your code was able to retrieve data by then
or
You can use Windows sockets functionality to get time data from the NTP server, and give your Socket code a timeout value of 5 secs.