• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 950
  • Last Modified:

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
0
diberi
Asked:
diberi
1 Solution
 
PeteEngineerCommented:
what do u mean by :



I would like to break this function if after 5 seconds is not possible get the time from web."
0
 
Vikram Singh SainiSoftware Engineer cum AD DeveloperCommented:
(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.
0
 
Jaime OlivaresSoftware ArchitectCommented:
you can launch a new thread with the time-acquisition function, and kill the thread (if still active) after some specific timeout value.
0
 
XMarshall10Commented:
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.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now