标签: timer

Winforms Timer for Dummies

我正试图让一个计时器在winform中每秒钟打一次,当我寻找关于如何做到这一点的建议我找到了大量关于线程的东西.好吧,我不关心线程,因为我所要做的就是让值在一分钟内从60倒数到0,然后停止.我认为我们不需要进入云计算来解决这个问题,但我真的是一个网络形式,所以我在这个问题上有点生疏.任何人都可以给我一个例子

这是我尝试过的

private void button1_Click(object sender, EventArgs e)
    {
        this.timeLeft = 60;
        this.label1.Visible = false;
        this.button1.Visible = false;
        gt = new Timer();
        gt.Tick += new EventHandler(CountDown);
        gt.Interval = 1000;
        gt.Start();
    }

private void CountDown(object sender, EventArgs e)
{
    do
    {
        this.TimeBar.Value = timeLeft;                
        this.timeLeft -= 1;
    } while (this.timeLeft > 0);
    if (this.TimeBar.Value > 0) return;
    gt.Stop();
    this.label1.Visible = true;
    this.button1.Visible = true;
}
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激.

timer winforms

16
推荐指数
2
解决办法
2万
查看次数

Windows批处理文件中的计时器

有人能指出我在Windows批处理文件中添加计时器的方法吗?我需要跟踪批次从开始运行的时间.

windows time cmd timer batch-file

16
推荐指数
3
解决办法
3万
查看次数

如何在mysql命令行中看到高精度查询时间?

我正在完成一些优化工作,我注意到在一些mysql转储中人们发表文章和问题(现在我实际上找不到了),有高精度执行时间(0.05985215秒)而不是0.06秒).

如何在命令行上查看这些更精确的查询时间?

编辑

这样的例子是:

+----------+
| COUNT(*) |
+----------+
| 11596    |
+----------+
1 row in set (0.05894344 sec)
Run Code Online (Sandbox Code Playgroud)

使用分析使我成为那里的一部分,但产生的输出太长,我必须记住启用它.我只是在寻找一个简单的高精度持续时间.

SET profiling = 1;
<query>
SHOW PROFILES;
Run Code Online (Sandbox Code Playgroud)

给我这样的东西:

+----------------------+-----------+
| Status               | Duration  |
+----------------------+-----------+
| (initialization)     | 0.000005  |
| checking permissions | 0.00001   |
| Opening tables       | 0.000499  |
| Table lock           | 0.000071  |
| preparing            | 0.000018  |
| Creating tmp table   | 0.00002   |
| executing            | 0.000006  |
| Copying to tmp table …
Run Code Online (Sandbox Code Playgroud)

mysql precision timer command-line-interface

16
推荐指数
2
解决办法
9170
查看次数

暂停计时器,然后继续

请参阅@Yuri从此处发布的代码.如何在一定次数后停止计时器 .如果我想因某些条件而停止它,然后再重新启动它.我该怎么做呢?

    private final static int DELAY = 10000;
    private final Handler handler = new Handler();
    private final Timer timer = new Timer();
    private final TimerTask task = new TimerTask() {
        private int counter = 0;
        public void run() {
            handler.post(new Runnable() {
                public void run() {
                    Toast.makeText(MainActivity.this, "test", Toast.LENGTH_SHORT).show();
                }
            });
            if(++counter == 4) {
                timer.cancel();
            }

    //do some stuff in my app
   //restart the timer again

        }
    };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        timer.schedule(task, …
Run Code Online (Sandbox Code Playgroud)

java android timer

16
推荐指数
2
解决办法
6万
查看次数

降低linux内核定时器频率

当我以Gentoo作为客户运行我的虚拟机时,我发现tick_periodic功能有相当大的开销.(这是在每个定时器中断上运行的函数.)此函数更新导致开销的全局jiffy使用write_seqlocks.

这是HZ我的内核配置文件中的grep 和相关内容.

sharan013@sitmac4:~$ cat /boot/config | egrep 'HZ|TIME'

# CONFIG_RCU_FAST_NO_HZ is not set
CONFIG_NO_HZ=y
# CONFIG_HZ_100 is not set
# CONFIG_HZ_250 is not set
# CONFIG_HZ_300 is not set
CONFIG_HZ_1000=y
CONFIG_HZ=1000
# CONFIG_MACHZ_WDT is not set
CONFIG_TIMERFD=y
CONFIG_HIGH_RES_TIMERS=y
CONFIG_X86_CYCLONE_TIMER=y
CONFIG_HPET_TIMER=y
Run Code Online (Sandbox Code Playgroud)

显然它已将配置设置为1000,但是当我这样做时sysconf(_SC_CLK_TCK),我得到100作为我的计时器频率.那么我系统的定时器频率是多少?

我想要做的是将频率降低到100,如果可能的话甚至更低.虽然它可能影响poll/ select和调度程序时间片的交互性和精度,但我准备牺牲这些东西以减少定时器中断,因为它会加速VM.

当我试图找出必须完成的工作时,我在某个地方读到你可以通过更改配置文件来实现这一点,否则在那里我读到将bootider = 10添加到boot参数就完成了工作,否则我在那里读到了如果您可以设置CONFIG_HIGH_RES_TIMERS即使不增加定时器频率的触发低延迟定时器也不需要,并且使用无定时系统也是如此CONFIG_NO_HZ.

我对于什么是正确的方法感到非常困惑.

我想要的是将定时器中断降低到尽可能低的程度.

我能知道这样做的正确方法吗?

linux timer linux-kernel

16
推荐指数
1
解决办法
2万
查看次数

Linux内核add_timer的可靠性在一个jiffy的分辨率?

在下面给出的代码中,有一个简单的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)

linux timer linux-kernel

16
推荐指数
1
解决办法
5265
查看次数

计时器在背景中

我正在为大学工作开发Android应用程序.在这项工作中,我想用计时器创建一个后台服务,当我关闭应用程序时,计时器仍在运行.当我打开应用程序时,我可以看到自我开始服务以来的时间.好吧,我的问题是当我关闭应用程序时,后台计时器停止而不是增加更多.

你能帮我吗?非常感谢

我的发射器课程

    import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

    private Button startButton;
    private Button pauseButton;

    private TextView timerValue;

    Intent intent;
    long timeSwapBuff = 0L;
    long updatedTime = 0L;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        timerValue = (TextView) findViewById(R.id.timerValue);

        startButton = (Button) findViewById(R.id.startButton);
        startButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {
                intent = new Intent(MainActivity.this, CounterService.class);
                startService(intent);
                registerReceiver(broadcastReceiver, new …
Run Code Online (Sandbox Code Playgroud)

android timer android-service

16
推荐指数
1
解决办法
2万
查看次数

检查CountDownTimer是否正在运行

我一直在寻找一种方法来查看CountDownTimer是否正在运行,但我无法找到方法,任何帮助将不胜感激

if (position == 0) {

    mCountDown = new CountDownTimer((300 * 1000), 1000) {

        public void onTick(long millisUntilFinished) {
            mTextField.setText("seconds remaining: "
                    + millisUntilFinished / 1000);
        }

        public void onFinish() {
            mTextField.setText("0:00");
            String path = "/sdcard/Music/ZenPing.mp3";
            try {

                mp.reset();
                mp.setDataSource(path);
                mp.prepare();
                mp.start();

            } catch (IOException e) {
                Log.v(getString(R.string.app_name),
                        e.getMessage());
            }
        }
    }.start();

}
Run Code Online (Sandbox Code Playgroud)

为此,我如何检查mCountDown当前是否正在运行?

android timer countdowntimer

16
推荐指数
1
解决办法
1万
查看次数

在Windows服务中运行的线程中最终不会执行

任何人都可以解释为什么这个finally块没有被执行?我已经阅读了关于何时期望最终阻止不被执行的帖子,但这似乎是另一种情况.此代码需要TopShelf和log4net.我正在运行.net 4.5

我想它必须是Windows服务引擎启动未处理的异常,但为什么它在finally块完成之前运行?

using log4net;
using log4net.Config;
using System;
using System.Threading;
using Topshelf;

namespace ConsoleApplication1
{
    public class HostMain
    {
        static void Main(string[] args)
        {
            HostFactory.Run(x =>
            {
                x.Service<HostMain>(s =>
                {
                    s.ConstructUsing(name => new HostMain());
                    s.WhenStarted(tc => tc.Start());
                    s.WhenStopped(tc => tc.Stop());
                });

                x.RunAsLocalSystem();
                x.SetServiceName("TimerTest");
            });
        }

        public void Stop()
        {
            LogManager.GetLogger("MyLog").Info("stopping");
        }

        public void Start()
        {
            XmlConfigurator.Configure();

            LogManager.GetLogger("MyLog").Info("starting");

            new Thread(StartServiceCode).Start();
        }

        public void StartServiceCode()
        {
            try
            {
                LogManager.GetLogger("MyLog").Info("throwing");

                throw new ApplicationException();
            }
            finally
            {
                LogManager.GetLogger("MyLog").Info("finally");
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

输出 …

c# windows-services timer try-catch-finally

16
推荐指数
1
解决办法
1666
查看次数

Timer.scheduledTimer在Swift 3中不起作用

我想func adjustmentBestSongBpmHeartRate() 每1.1秒调用一次方法.我用过Timer,但它不起作用.我已阅读该文档并发现了大量示例代码,它仍然可以正常工作!我错过了什么吗?

 timer = Timer.scheduledTimer(timeInterval: 1.1, target: self, selector: #selector(self.adjustmentBestSongBpmHeartRate), userInfo: nil, repeats: false)
 timer.fire()

 func adjustmentBestSongBpmHeartRate() {
    print("frr")
 }
Run Code Online (Sandbox Code Playgroud)

timer ios swift swift3

16
推荐指数
5
解决办法
3万
查看次数