我在我的项目中使用某种秒表而且我有
start time ex: 18:40:10 h
stop time ex: 19:05:15 h
Run Code Online (Sandbox Code Playgroud)
我需要这两个值的结果 final time = stop - start
我找到了一些例子,但它们都非常令人困惑.
有没有简单的解决方案?
我正在寻找iPhone的高分辨率计时代码,以便做一些性能计时.我想写这样的代码:
HighResolutionTimer* myTimer = [[HighResolutionTimer alloc]init];
[myTimer start];
[self doSomeLengthyOperation];
NSLog( @"doSomeLengthyOperation took %f seconds", [myTimer elapsedTime] );
Run Code Online (Sandbox Code Playgroud) 我想开发一个Windows控制台应用程序,它在给定时间后定期执行一个动作.我已经读过某个计时器类仅适用于Windows窗体应用程序,那么实现我想要的最佳方法是什么?
我有一个Android应用程序,它有单独的东西,但基本上都是线程(绝对是Android调试器的线程)
有多个动画侦听器可以相互循环和调用
倒计时器在启动后总是倒计时到零
现在我需要考虑添加更多的倒计时器.我可以进行多少这种循环过程?在这个特定的实现中,我不关心性能,效率等,直到它变得明显.
洞察力赞赏
是否有新的Timer API允许我这样做?
await timer.wait(500);
Run Code Online (Sandbox Code Playgroud)
基本上,要睡眠X ms然后继续执行其余的功能
为什么没有java.util.Timer对象的isCancelled方法?
如果Timer没有被取消,我想安排一个任务,并且如果它被取消,则直接运行它(在同一个线程上).
IllegalStateException如果Timer已被取消,是否可以捕获可能出现的唯一选项?(抓到一个感觉不对IllegalStateException).
我刚碰到这个代码,我不明白.是否有理由使用此设计而不是仅使用AutoReset重新运行已用代码?
private readonly Timer Timer = new Timer();
protected override void OnStart(string[] args)
{
Logger.InfoFormat("Starting {0}.", ServiceName);
try
{
// If Enabled is set to true and AutoReset is set to false, the Timer raises the Elapsed event only once, the first time the interval elapses.
Timer.AutoReset = false;
Timer.Elapsed += Timer_Elapsed;
Timer.Interval = Settings.Default.ScriptingStatusLifeTime;
Timer.Start();
}
catch (Exception exception)
{
Logger.ErrorFormat("An error has occurred while starting {0}.", ServiceName);
Logger.Error(exception);
throw;
}
}
/// <summary>
/// Whenever the Schedule Service …Run Code Online (Sandbox Code Playgroud) //Creates a new Timer which may be specified to be run as a daemon thread.
Timer(boolean isDaemon)
//Creates a new non-daemon Timer.
Timer()
Run Code Online (Sandbox Code Playgroud)
什么时候应该在Android应用程序中作为守护进程启动计时器?
文档没有说明它.
我想要一种创建本地iOS-time-hack proof背景倒计时器的方法,例如用于计算游戏中下一个奖励的停机时间.
对象的解释:
本地
- 没有互联网连接的作品
native-iOS
- 我想在(最好)Objective-C或Swift中找到解决方案
time-hack proof
- 当用户向前/向后更改设备时间时,剩余时间保持不变
背景
- 关闭/重新打开友好
倒计时器
- 一个计时器,它在启动后将提供一种检查剩余时间的方法
我希望在我的iOS游戏中有一个基于时间的奖励系统,仅仅通过移动设备时间就不会轻易攻击.
本来,我认为这是不可能的,使用保持[NSDate date]和savedDate,比较它们一起找经过的时间.然而,最近我遇到了一个使用此功能的游戏:Crossy Road.据我所知,这是一款Unity游戏,但是我怀疑在Unity项目中可以使用的这种有点普遍的功能是在iOS上通过Objective-C或Swift访问的.
他们提供定时奖励系统,每6个小时一次,并且,据我测试,它不会通过更改设备时间来破解.它也适用于没有互联网连接.(如果你没有连接,我不确定它是否有效,但是当我连接,断开连接并尝试使用黑客时,它不起作用.)
我正在尝试做一个可以让计时器在后台运行的应用程序.
这是我的代码:
let taskManager = Timer.scheduledTimer(timeInterval: 10, target: self, selector: #selector(self.scheduleNotification), userInfo: nil, repeats: true)
RunLoop.main.add(taskManager, forMode: RunLoopMode.commonModes)
Run Code Online (Sandbox Code Playgroud)
上面的代码将执行一个将调用本地通知的函数.当应用程序处于前台时,这是有效的,如何让它在后台运行?
我试图放几条打印线,我看到当我最小化(按下主页按钮)应用程序时,计时器停止,当我回到应用程序时,它恢复.
我希望计时器仍然在后台运行.有办法吗?
这就是我想要发生的事情:
运行应用程序 - >等待10秒 - >收到通知 - >等待10秒 - >收到通知 - >然后返回等待再次收到
在前景时发生.但不是在后台.请帮助.
timer ×10
android ×3
c# ×3
ios ×2
java ×2
objective-c ×2
swift ×2
.net ×1
action ×1
async-await ×1
c#-5.0 ×1
cancellation ×1
iphone ×1
listener ×1
subtraction ×1