c# - 在 C# 中即发即弃

标签 c#

C# 中是否有任何事件,例如每一分钟都发生火灾并忘记???

每分钟触发一次此方法。

    public void Earning()
    {
        var data= new Bussinesslayer().Getdata();
    }

最佳答案

您可以使用 Timer 类:
声明:

System.Timers.Timer _tmr;

初始化:

_tmr = new System.Timers.Timer();

设置:

//Assigning the method that will be called
_tmr.Elapsed += new System.Timers.ElapsedEventHandler(tmr_Elapsed);
//Setting the interval (in milliseconds):
_tmr.Interval = 1000;

开始计时:

_tmr.Start();

将具有与以下示例中相同签名的函数:

void tmr_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
  this.Earning();
  //please note that here you are in another thread.
}

如果你想停止定时器,你可以使用:

_tmr.Stop();

关于c# - 在 C# 中即发即弃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16931432/

相关文章:

c# - MailAddress:在邮件 header 中发现无效字符

c# - 将来自 webform 的物理标签存储到列表 C#

c# - 如何为 SQLite 创建身份服务器数据库?

c# - 如何在 C# 中编码包含 DWORD 位域的 C++ 结构

c# - 如何获取进程使用的CPU周期数

c# - 如何通知组件或子游戏对象已添加到游戏对象

c# - 验证正在等待任务

c# - 给定 IP 地址和子网掩码,如何计算 CIDR?

c# - 如何获取受 ExecuteNonQuery 影响的行数并忽略触发器行?

c# - 从数据表(Windows 窗体)填充 ListView 或列表框