我确实有一个检查功能,一旦打开应用程序就会运行。如何让它像每 20 秒自动运行该功能一样?
Main()
{
Checking();
}
public void Checking() // run this function every 20 seconds
{ // some code here
}
我确实有一个检查功能,一旦打开应用程序就会运行。如何让它像每 20 秒自动运行该功能一样?
Main()
{
Checking();
}
public void Checking() // run this function every 20 seconds
{ // some code here
}
您可以使用 C# Timer 类
public void Main()
{
var myTimer = new Timer(20000);
myTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
myTimer.Enabled = true;
Console.ReadLine();
}
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
Console.WriteLine("The Elapsed event was raised at {0}", e.SignalTime);
}
Main()
{
Timer tm = new Timer();
tm.Interval = 20000;//Milliseconds
tm.Tick += new EventHandler(tm_Tick);
tm.Start();
}
void tm_Tick(object sender, EventArgs e)
{
Checking();
}
public void Checking()
{
// Your code
}