Solved

C# Run time limit for function

Posted on 2010-09-05
4
877 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now