我想制作我的iOS应用程序,可以每5分钟执行一次特定的功能.怎么做?功能很简单,就像
batter = 95; // will be calculated.. every time is differ
[UIApplication sharedApplication].applicationIconBadgeNumber = batter;
Run Code Online (Sandbox Code Playgroud)
我需要在后台为它制作计时器
我有这个计时器用于Star.png通过JFrame & JPanel
移动具有计时器的星的功能:
private final static int HEIGHT = 300;
.
.//more code here
.
.
x=y=0;
.
.
public void downRight() {
Timer localTimer = new Timer(100, null);
localTimer.setRepeats(false);
localTimer.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
x++;
y++;
repaint();
}
});
int xTest=0;
while (y < HEIGHT) {
System.out.println("x "+(++xTest)+" y "+y);
localTimer.start();
}
System.out.println("Reached");
}
Run Code Online (Sandbox Code Playgroud)
运行计时器并测试xTest时,y值发现以下内容:
x 1 y 0
x 2 y 0
x 3 y 0
..... More Outputs here …Run Code Online (Sandbox Code Playgroud) 我有这个代码块,它给我发出以下错误:
this.modifyAspect('health');
^
TypeError: Object #<Timer> has no method 'modifyAspect'
at Timer.tick (/Users/martinluz/Documents/Nodes/societ/node_modules/societal/societal.js:93:9)
at Timer.exports.setInterval.timer.ontimeout (timers.js:234:14)
Run Code Online (Sandbox Code Playgroud)
我已经打过电话modifyAspects()的Societ.modifyAspects,this.modifyAspects()而且modifyAspects(),也只有得到了错误.任何帮助或建议表示赞赏......
这是代码:
var Societ = function(inboundConfig){
this.population = undefined;
this.owner_id = undefined;
this.owner_name = undefined;
this.config = inboundConfig;
this.aspects = {
education:{
facilities: undefined,
rating: undefined
},
health: {
facilities: undefined,
rating: undefined
}
};
this.modifiers = {
health: 1,
education: 2,
population: 2
};
this.tickio = function(){
console.log('tickio');
}
return{
config: this.config,
bootstrap: function(){
this.owner_id …Run Code Online (Sandbox Code Playgroud) 请查看以下代码
public class Test {
public Test()
{
Timer timer = new Timer();
timer.schedule(new TimerTask(){
public void run()
{
System.out.println("Updated");
}
}, System.currentTimeMillis(),1000);
}
public static void main(String[]args)
{
new Test();
}
}
Run Code Online (Sandbox Code Playgroud)
在这里,你可以看到它没有打印任何东西!换句话说,时间没有安排!这是为什么?我想安排任务在每一秒发生.请帮忙!
我明天早上必须提交我的WPF项目; 它在VS 2010中运行得很好,但是在使用C#的VS 2008(两种情况下都是.NET 3.5)中出错了.
我正在使用计时器,Dispatcher.Invoke但在VS 2008中它给出错误:
错误163
最佳重载方法匹配System.Windows.Threading.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority, System.Delegate)包含一些无效参数.
以下代码给出错误:
Dispatcher.Invoke(new Action(() =>
{
// ANY ACTIONS HERE
.. some task
}), null);
Run Code Online (Sandbox Code Playgroud)
代码必须在VS 2008中运行.
我将如何使用DispatcherTimer每5秒检查外部程序是否正在运行.如果它正在运行,那么button1将被禁用.
我在Windows窗体C#中使用Thread.Sleep.使用哪个导致没有响应表格.使用Timer也不符合我的目的.
示例代码:
if(......) // There are many if with difrent components and many Thread.sleep
{
button.visible=true;
Thread.sleep(1000);
GotoMeasurementMode(3000);
Thread.sleep(3000);
query(device.Text);
Thread.sleep(7000);
StopMeasurement();
Thread.sleep(4000);
}
Run Code Online (Sandbox Code Playgroud)
使用上面的代码会导致形式无响应.使用Timer会产生嵌套计时器.而且在我的情况下并不成功.请告诉我Windows窗体的另一种选择.想要命令之间的特定暂停.
我有一个程序,它的'唯一的动作是每24小时调用一个函数.显然,我一直在努力为这个原因使用计时器.但是程序在第一次调用函数之前结束(因为主线程首先结束).有没有一种方法可以让计时器保持活力?
我希望第二次打印在2秒后发生.
System.out.println("First print.");
//I want the code that makes the next System.out.println in 2 seconds.
System.out.println("This one comes after 2 seconds from the println.");
Run Code Online (Sandbox Code Playgroud) 我试图让HTML页面使用JavaScript的setInterval函数每秒更新一个包含文本文件内容的textarea.但是,setInterval调用中的函数似乎只运行一次.
使用Javascript:
// Send a GET request to the given location
function sendRequest(location, nonblocking) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", location, nonblocking);
xmlhttp.send();
return xmlhttp.responseText;
}
// Refresh the communication log
function refreshLog() {
document.getElementById("comm_log").value = sendRequest("src/log.txt", false);
}
window.setInterval(refreshLog, 1000);
Run Code Online (Sandbox Code Playgroud)
请求不是异步的,因为文本文件永远不会很长,这是我试图快速拼凑的东西.
HTML:
<html>
<head>
<style type="text/css">
textarea {
width: 98%;
height: 80%;
resize: none;
font-family: "Courier New";
}
</style>
<script type="text/javascript" src="src/script.js"></script>
</head>
...
<textarea id="comm_log" readonly></textarea>
...
</html>
Run Code Online (Sandbox Code Playgroud)
有人有想法吗?