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
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
(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.
(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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
I would like to break this function if after 5 seconds is not possible get the time from web."