Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C# Run time limit for function

Posted on 2010-09-05
4
Medium Priority
?
916 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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

971 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