每隔1秒触发一次事件怎样确定?

littlerainsnow 2004-08-05 07:49:22
1秒怎么的来?
...全文
247 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
gbbword 2004-08-07
  • 打赏
  • 举报
回复
用DateTime.Now.Ticks来获得timer控件的运行的时间刻度值,这样就可以精确很多了!我估计可能达到微秒级或者更短!
yebigroc 2004-08-06
  • 打赏
  • 举报
回复
参考一个例子

public class Class1 {
static System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
static int alarmCounter = 1;
static bool exitFlag = false;

// This is the method to run when the timer is raised.
private static void TimerEventProcessor(Object myObject,
EventArgs myEventArgs) {
myTimer.Stop();

// Displays a message box asking whether to continue running the timer.
if(MessageBox.Show("Continue running?", "Count is: " + alarmCounter,
MessageBoxButtons.YesNo) == DialogResult.Yes) {
// Restarts the timer and increments the counter.
alarmCounter +=1;
myTimer.Enabled = true;
}
else {
// Stops the timer.
exitFlag = true;
}
}

public static int Main() {
/* Adds the event and the event handler for the method that will
process the timer event to the timer. */
myTimer.Tick += new EventHandler(TimerEventProcessor);

// Sets the timer interval to 5 seconds.
myTimer.Interval = 5000;
myTimer.Start();

// Runs the timer, and raises the event.
while(exitFlag == false) {
// Processes all the events in the queue.
Application.DoEvents();
}
return 0;
}
}
tendotnet 2004-08-05
  • 打赏
  • 举报
回复
看一下一楼的,把INTERVAL=1,不就行了。
littlerainsnow 2004-08-05
  • 打赏
  • 举报
回复
我的意思是有没有像java那样可以取得毫秒级的时间间隔,用控件对效率肯定有影响吧
butterdog 2004-08-05
  • 打赏
  • 举报
回复
呵呵,连这还嫌复杂!
标记,一下,
看有没有更好的解决方法。:)
littlerainsnow 2004-08-05
  • 打赏
  • 举报
回复
不需要那么复杂吧,我只想得到1秒的时间
yebigroc 2004-08-05
  • 打赏
  • 举报
回复
Timer控件
timer的interval设为1000

amami 2004-08-05
  • 打赏
  • 举报
回复
这10分还有这多人!算了
efeng4209 2004-08-05
  • 打赏
  • 举报
回复
timer的interval设为1000
triout 2004-08-05
  • 打赏
  • 举报
回复
使用Timer控件.

设置:

ENABLE=TRUE

设置:

INTERVAL=1000(毫秒)

然后对TIMER对象的ONTIMER编程。

110,546

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧