2011-05-05 162 views
-1

嗨,我可以知道如何将下面的内容更改为c#?
SetTimer(2,100,NULL);需要转换帮助

什么是SetTimer在C#中?

+0

请问你说什么是你的要求 – anishMarokey 2011-05-05 14:26:23

+2

我们需要更多的上下文:你想完成什么?这条线的代码是干什么的? – Chad 2011-05-05 14:26:25

+0

[将SetTimer()和KillTimer()移植到C#的可能的重复?](http://stackoverflow.com/questions/5749925/porting-settimer-and-killtimer-to-c) – 2011-05-05 14:27:56

回答

0
  static void Start() { 
       var timer = new Timer(3000); 
       timer.Elapsed += new ElapsedEventHandler(_timer_Elapsed); 
       timer.Enabled = true; 
      } 
      static void _timer_Elapsed(object sender, ElapsedEventArgs e) { 
       //do stuff at interval 
      } 
+0

这是不正确的。 'SetTimer'创建一个周期性的定时器。它不会让线程睡眠。 – 2011-05-05 14:29:22

1

我假设你正在编写Windows窗体程序。要转换的SetTimer(2,100,NULL)函数会创建一个Windows计时器,该计时器将每隔100毫秒发布一次WM_TIMER消息到窗口。

要在Windows窗体程序中获得该功能,请在窗体上放置一个Windows Forms Timer。将其周期设置为100毫秒,然后为Elapsed事件编写事件处理程序。