timer

Swift 4 Timer Crashes with NSException

陌路散爱 提交于 2020-02-14 00:42:23
问题 I've been searching for a way to use a Timer in Swift 4 and looked at this article. I test out my code in xcode and when the the timer first ticks (in this case after 10 seconds) the app crashes and I get an error, although the build succeeded. 2017-11-20 19:54:42.781502-0700 Rock Prodigy[3022:554505] -[_SwiftValue tick]: unrecognized selector sent to instance 0x608000051520 2017-11-20 19:54:42.791278-0700 Rock Prodigy[3022:554505] *** Terminating app due to uncaught exception

Reliable timer in a console application

ぐ巨炮叔叔 提交于 2020-02-13 04:07:07
问题 I am aware that in .NET there are three timer types (see Comparing the Timer Classes in the .NET Framework Class Library ). I have chosen a threaded timer as the other types can drift if the main thread is busy, and I need this to be reliable. The way this timer works in the control of the timer is put on another thread so it can always tick along with the work begin completed on the parent thread when it is not busy. The issue with this timer in a console application is that while the timer

replace a UIview animation by a timer animation

淺唱寂寞╮ 提交于 2020-02-08 10:19:32
问题 well here is my code : - (CGPoint)randomPointSquare { CGRect frame = [[self view] frame]; //CGFloat rand_x = ((float)arc4random() / (float)UINT_MAX) * (float)_window.frame.size.width; NSInteger side = arc4random() / (UINT_MAX/4); CGFloat offset = 0; switch(side) { case 0: /* top */ offset = ((float)arc4random() / (float)UINT_MAX) * (float)frame.size.width; return CGPointMake(offset, -10); case 1: /* bottom */ offset = ((float)arc4random() / (float)UINT_MAX) * (float)frame.size.width; return

how to solve this multiple linux timer with single signal handler

我怕爱的太早我们不能终老 提交于 2020-02-08 00:50:24
问题 /*The handler checks that the value stored in sival_ptr matches a given timerID variable. The sival_ptr is the same as the one we set in makeTimer(), though here it lives in a different structure. Obviously, it got copied from there to here on the way to this signal handler. The point is that the timerID is what is used to determine which timer just went off and determine what to do next */ static void timerHandler( int sig, siginfo_t *si, void *uc ) { timer_t *tidp; tidp = si->si_value.sival

How to generate random numbers at set time intervals?

为君一笑 提交于 2020-02-06 05:13:06
问题 I have developed code in Java for generating ten random numbers from a range 0 to 99. The problem is I need to generate a random number for every 2 min. I am new to this area and need your views. 回答1: This example adds a random number to a blocking dequeue every two minutes. You can take the numbers from the queue when you need them. You can use java.util.Timer as a lightweight facility to schedule the number generation or you can use java.util.concurrent.ScheduledExecutorService for a more

How to execute a method every second on a background thread so it doesn't affect the performance of the app

帅比萌擦擦* 提交于 2020-02-05 04:25:09
问题 I am trying to access my database every 30 seconds, however, whenever the method executes I can clearly see a performance dip in the application. So far this is my current code: var timer = Timer() override func viewDidLoad() { super.viewDidLoad() scheduledTimerWithTimeInterval() } func scheduledTimerWithTimeInterval(){ timer = Timer.scheduledTimer(timeInterval: 30, target: self, selector: #selector(self.updateCounting), userInfo: nil, repeats: true) } @objc func updateCounting(){

Python - Alternative to time.sleep

扶醉桌前 提交于 2020-02-04 08:06:15
问题 Hello is there a alternative to time.sleep? Because I want to let my LEDs blink in the exact amount of Hz what is not able because to call time.sleep needs time too, so the blinking needs more time than expected. #!/usr/bin/python import RPi.GPIO as GPIO import time from threading import Thread GPIO.setmode(GPIO.BOARD) GPIO.setup(32, GPIO.IN) def blink(port, hz): GPIO.setup(port, GPIO.OUT) while True: if GPIO.input(32) == 1: //lever activated? GPIO.output(port, GPIO.HIGH) time.sleep(0.5/hz)

Python - Alternative to time.sleep

偶尔善良 提交于 2020-02-04 08:06:08
问题 Hello is there a alternative to time.sleep? Because I want to let my LEDs blink in the exact amount of Hz what is not able because to call time.sleep needs time too, so the blinking needs more time than expected. #!/usr/bin/python import RPi.GPIO as GPIO import time from threading import Thread GPIO.setmode(GPIO.BOARD) GPIO.setup(32, GPIO.IN) def blink(port, hz): GPIO.setup(port, GPIO.OUT) while True: if GPIO.input(32) == 1: //lever activated? GPIO.output(port, GPIO.HIGH) time.sleep(0.5/hz)

How to get the sum of time from database? [duplicate]

北城以北 提交于 2020-02-02 12:27:04
问题 This question already has an answer here : How to get the sum of time from database in PHP? (1 answer) Closed 5 years ago . I wanted to get the sum of this column in my database and display it in home page. I use this code to save data on my Database $timeanddate=$_POST['timeanddate']; $time=$_POST['tst']; $name=$_POST['name']; $number=$_POST['number']; $disposition=$_POST['disposition']; $remarks=$_POST['remarks']; $times=$_POST['timetoday']; $dates=$_POST['datetoday']; if(isset($_POST[

How reliable are .net timers?

人走茶凉 提交于 2020-02-01 05:12:06
问题 I'm looking at using a System.Timers.Timer in a windows service. I would like to know how reliable and accurate they are. In particular: Are there any guarantees about how often they will run? What happens when the processor or memory are overloaded? Will the ElapsedEventArgs.SignalTime always be accurate under such circumstances? If a timer is run for a long time, what happens when corrections are made to the system time to take into account inaccuracies in the system clock? Update: Thanks