简体   繁体   English

C#:在C#中是否有来自Java的等效类TimerTask?

[英]C#: is there an equivalent class of TimerTask from Java in C#?

I am looking if there is an equivalent class of TimerTask from Java in C#? 我正在寻找在C#中是否存在来自Java的等效类TimerTask?

The TimerTask of Java is referenced to here: http://download.oracle.com/javase/1.4.2/docs/api/java/util/TimerTask.html 这里引用了TimerTask的Java: http//download.oracle.com/javase/1.4.2/docs/api/java/util/TimerTask.html

Thanks in advance. 提前致谢。

The purpose of this is that I need to implement some code following in C#: 这样做的目的是我需要在C#中实现一些代码:

import java.util.Timer;
import java.util.TimerTask;

private static Timer timer = new Timer();

private TimerTask timeoutTask;

if (timeoutTime>0)
{
  timeoutTask = new TimerTask() { 
    public void run() 
    {
      // callActivity();
    }
  };
}

timer.schedule( timeoutTask, timeoutTime);

If you could provide me an equivalent code in C#, that would be great! 如果你能在C#中为我提供一个等效的代码,那就太好了! Thanks in advance 提前致谢

Sounds like System.Timers.Timer . 听起来像System.Timers.Timer There are four common timer types in .NET: .NET中有四种常见的计时器类型:

  • System.Windows.Forms.Timer for timers in WinForms apps System.Windows.Forms.Timer for WinForms应用程序中的计时器
  • System.Windows.DispatcherTimer for timers in WPF/Silverlight apps 用于WPF / Silverlight应用程序中的计时器的System.Windows.DispatcherTimer
  • System.Threading.Timer
  • System.Timers.Timer

This article compares all but DispatcherTimer. 本文比较了DispatcherTimer以外的所有内容。

如果你想安排任务,然后有一个很好的开源库在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM