在下面给出的代码中,有一个简单的Linux内核模块(驱动程序),它add_timer以1 jiffy的分辨率重复调用一个函数10次(也就是说,计时器计划发射jiffies + 1).使用该bash脚本rerun.sh,然后从打印输出中获取时间戳syslog,并使用它来显示它们gnuplot.
在大多数情况下,我得到这样的syslog输出:
[ 7103.055787] Init testjiffy: 0 ; HZ: 250 ; 1/HZ (ms): 4
[ 7103.056044] testjiffy_timer_function: runcount 1
[ 7103.060045] testjiffy_timer_function: runcount 2
[ 7103.064052] testjiffy_timer_function: runcount 3
[ 7103.068050] testjiffy_timer_function: runcount 4
[ 7103.072053] testjiffy_timer_function: runcount 5
[ 7103.076036] testjiffy_timer_function: runcount 6
[ 7103.080044] testjiffy_timer_function: runcount 7
[ 7103.084044] testjiffy_timer_function: runcount 8
[ 7103.088060] testjiffy_timer_function: runcount 9
[ 7103.092059] testjiffy_timer_function: runcount …Run Code Online (Sandbox Code Playgroud) 我正在尝试重建一个旧的节拍器应用程序,该应用程序最初使用C++中的MFC编写,使用C#在.NET中编写.我遇到的一个问题是让计时器足够准确地"打勾".
例如,假设一个简单的BPM(每分钟节拍数)为120,则计时器应每隔0.5秒(或500毫秒)打勾.然而,使用它作为刻度的基础并不完全准确,因为.NET只能保证计时器在经过的时间过去之前不会打勾.
目前,为了解决上面使用的相同的120 BPM示例,我将刻度设置为100毫秒,并且仅在每5个计时器刻度上播放点击声.这确实提高了准确度,但如果感觉有点像黑客.
那么,获得准确滴答的最佳方法是什么?我知道有更多的计时器可用于Visual Studio中随时可用的Windows窗体计时器,但我并不熟悉它们.
在Linux上编译调用POSIX定时器函数的程序(例如:timer_create,timer_settime)会返回错误,例如:
In function `foo': timer.c:(.text+0xbb): undefined reference to `timer_create' timer.c:(.text+0x187): undefined reference to `timer_settime' collect2: ld returned 1 exit status
我需要链接哪个库?
可能重复:
对Python中的Cron调度程序的建议?
安排函数作为后台任务定期运行的最pythonic方法是什么?有一些想法在这里,但他们似乎都比较难看我.而且不完整.
java Timer类有一个非常完整的解决方案.有人知道类似的python类吗?
请考虑以下代码:
class TestTimerGC : Form
{
public TestTimerGC()
{
Button btnGC = new Button();
btnGC.Text = "GC";
btnGC.Click += (sender, e) => GC.Collect();
this.Controls.Add(btnGC);
System.Windows.Forms.Timer tmr = new System.Windows.Forms.Timer();
tmr.Interval = 1000;
tmr.Tick += (sender, e) => this.Text = DateTime.Now.ToString();
tmr.Start();
}
}
Run Code Online (Sandbox Code Playgroud)
如果我没有弄错,在tmr变量超出范围之后,Timer就不会在任何地方引用它,因此它应该有资格进行垃圾收集.但是当我点击GC按钮时,计时器继续运行,所以我猜它没有被收集......
有没有人对此有解释?
PS:当然,这不是一个真正的程序,我只是想向别人证明一点...但我的证据不起作用;)
我想使用c#使用最高分辨率计时器.例如,我想每11个刻度提升一个事件(我听说刻度是pc中最高的计数器).我试过计时器,发现最小经过时间以毫秒为单位.我看了秒表,但秒表不会引发事件.
谢谢.
假设我有一个配置了10秒(10k ms)间隔的Windows窗体计时器:
myTimer.Interval = 10000;
Run Code Online (Sandbox Code Playgroud)
我想启动它并Tick马上启动它:
myTimer.Start();
myTimer_Tick(null, null);
Run Code Online (Sandbox Code Playgroud)
最后一行有效,但是有更好或更合适的方式吗?
我正在制作一个显示计时器的iOS应用程序.在用户按下主页按钮后,我不认为我可以保持计时器运行,所以我想记录用户退出应用程序的时间,并使用他们重新进入应用程序更新计时器的时间.这是我试过的代码:
- (void)applicationWillResignActive:(UIApplication *)application
{
double currentTime = CACurrentMediaTime();
NSLog(@"%g", currentTime);
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method …Run Code Online (Sandbox Code Playgroud) .NET System.Threading Timer类有几个重载的Change()方法,如果计时器成功更新,则返回"true";否则返回false.
参考:http://msdn.microsoft.com/en-us/library/yz1c7148.aspx
这种方法实际上是否真的返回false?什么会导致这返回错误?
我确实知道Timeout.InfiniteTimespan.NET 4.0中不存在.
注意到,Timeout.Infinite.NET 4.0中也存在这种情况
我叫这两种方法:
// the Change-Method
public bool Change(
TimeSpan dueTime,
TimeSpan period
)
// the Constructor of Timer
public Timer(
TimerCallback callback,
Object state,
TimeSpan dueTime,
TimeSpan period
)
Run Code Online (Sandbox Code Playgroud)
在某些情况下,dueTimeParameter必须是无限的,这意味着不会触发Event.我知道我可以简单地使用其他重载,但我觉得必须要更简单.
我已经尝试过使用new TimeSpan(0, 0, -1)或new TimeSpan(-1)作为dueTime.*但是这会引发ArgumentOutOfRangeException指向dueTime参数.
是否有可能创建一个像Timeout.InfiniteTimespan.NET 4.5 一样的文字?