Solved

C# Run time limit for function

Posted on 2010-09-05
4
884 Views
Last Modified: 2012-05-10
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
Comment
Question by:diberi
4 Comments
 
LVL 8

Expert Comment

by:PeteEngineer
ID: 33609045
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
 
LVL 16

Expert Comment

by:Vikram Singh Saini
ID: 33609061
(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
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 33609103
you can launch a new thread with the time-acquisition function, and kill the thread (if still active) after some specific timeout value.
0
 
LVL 1

Expert Comment

by:XMarshall10
ID: 33610338
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question