timer

Error: Property timer doesn't exist on type typeof Observable

廉价感情. 提交于 2020-01-12 05:25:07
问题 The code is below import {Component} from 'angular2/core'; import {Observable} from 'rxjs/Rx'; @Component({ selector: 'my-app', template: 'Ticks (every second) : {{ticks}}' }) export class AppComponent { ticks =0; click(){ let timer = Observable.timer(2000,1000); timer.subscribe(t=>this.ticks = t); } } But i am getting an error. The error is in the following line: let timer = Observable.timer(2000,1000); The definition of error is "property timer doesn't exist on type typeof Observable" Why

Unit test System.Threading.Timer in .NET

ⅰ亾dé卋堺 提交于 2020-01-12 04:40:07
问题 How to unit test a timer based on System.Threading.Timer in .NET The System.Threading.Timer has a callback method 回答1: You can unit-test it by not actually creating a direct dependency on System.Threading.Timer . Instead, create an ITimer interface, and a wrapper around System.Threading.Timer that implements it. First you need to convert the callback to an event, so that it can be made part of an interface: public delegate void TimerEventHandler(object sender, TimerEventArgs e); public class

What context does a Linux kernel timer function runs in?

跟風遠走 提交于 2020-01-12 03:31:21
问题 When a timer created with the add_timer API expires and the function assigned at the timer structure runs, in what context does it run? Is it interrupt context or some kernel process context? 回答1: It is of course in interrupt context, more precisely, in softirq context, see below (kernel/timer.c): static inline void __run_timers(struct tvec_base *base) { struct timer_list *timer; spin_lock_irq(&base->lock); while (time_after_eq(jiffies, base->timer_jiffies)) { struct list_head work_list;

Can you implement a timer without a “sleep” in it using standard c++/c++11 only?

给你一囗甜甜゛ 提交于 2020-01-11 19:57:03
问题 I have the following code (hand-copied in): // Simple stop watch class basically takes "now" as the start time and // returns the diff when asked for. class stop_watch {...} // global var std::thread timer_thread; void start_timer(int timeout_ms) { timer_thread = std::thread([timeout_ms, this](){ stop_watch sw; while (sw.get_elapsed_time() < timeout_ms) { // Here is the sleep to stop from hammering a CPU std::this_thread::sleep_for(std::chrono::milliseconds(10)); } // Do timeout things here..

Easy way to excecute method after a given delay?

放肆的年华 提交于 2020-01-11 19:56:26
问题 Is there a easy way to perform a method after a given delay like in iOS out of the box? On iPhone I would do this: [self performSelector:@selector(connectSensor) withObject:nil afterDelay:2.5]; It will then schedule the method connectSensor on the main thread (UI thread) to be executed after 2,5 seconds. And because it is automatically scheduled on the main thread, you don't have to worry about cross thread issues. (There is also a performSelectorOnBackground version) So how would I do this

Easy way to excecute method after a given delay?

瘦欲@ 提交于 2020-01-11 19:55:34
问题 Is there a easy way to perform a method after a given delay like in iOS out of the box? On iPhone I would do this: [self performSelector:@selector(connectSensor) withObject:nil afterDelay:2.5]; It will then schedule the method connectSensor on the main thread (UI thread) to be executed after 2,5 seconds. And because it is automatically scheduled on the main thread, you don't have to worry about cross thread issues. (There is also a performSelectorOnBackground version) So how would I do this

Can you implement a timer without a “sleep” in it using standard c++/c++11 only?

北战南征 提交于 2020-01-11 19:55:29
问题 I have the following code (hand-copied in): // Simple stop watch class basically takes "now" as the start time and // returns the diff when asked for. class stop_watch {...} // global var std::thread timer_thread; void start_timer(int timeout_ms) { timer_thread = std::thread([timeout_ms, this](){ stop_watch sw; while (sw.get_elapsed_time() < timeout_ms) { // Here is the sleep to stop from hammering a CPU std::this_thread::sleep_for(std::chrono::milliseconds(10)); } // Do timeout things here..

Java - updating existing stopwatch code to include countdown

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-11 13:55:20
问题 @HovercraftFullofEels was kind enough to help me by providing me the basis for the following code, which I made some modifications to (marked by "line completely added" comments and the giant comment at the end, which contains code to be placed somewhere in the file). The original file was a simple stopwatch, and my modifications are to include 3 JTextFields.that take in mins, secs, and CENTIseconds (1 centisecond = 1/100 of a second). I want to include a "Submit" button too, which allows the

Swing Timer stopwatch in Java

人走茶凉 提交于 2020-01-11 13:28:13
问题 Can someone provide me an example of a Swing Timer stopwatch GUI in Java using a constantly-updating JLabel? I am not familiar with using @Override, so please don't suggest code with that in it unless it is absolutely necessary (I've done other Swing Timers, such as a system clock, without it). Thanks! EDIT: As per @VGR's request, here's the code I have for my basic clock that uses a Swing Timer: import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event

java timer for game

孤街浪徒 提交于 2020-01-11 11:59:11
问题 I have created a game in java and now I just need to add a timer that allow the user to play under 60s. I have searched on internet and found the timer for swing and util packages. could you please just give me a method to be able to use it in my game??? 回答1: if you want something interactive you can use TimerTask and Timer classes: class ExpireTask extends TimerTask { YourClass callbackClass; ExpireTask(YourClass callbackClass) { this.callbackClass = callbackClass; } public void run() {