Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C语言中的火与遗忘#_C# - Fatal编程技术网

C# C语言中的火与遗忘#

C# C语言中的火与遗忘#,c#,C#,在C#中是否有任何事件,如每分钟发生一次火灾和遗忘 每分钟使用一次这种方法 public void Earning() { var data= new Bussinesslayer().Getdata(); } 您可以使用计时器类: 声明: System.Timers.Timer _tmr; 初始化: _tmr = new System.Timers.Timer(); //Assigning the method that will be calle

在C#中是否有任何事件,如每分钟发生一次火灾和遗忘

每分钟使用一次这种方法

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

您可以使用计时器类:
声明:

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 = 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();

您可以使用计时器类:
声明:

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 = 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();
您将需要包括以下内容:

using System;
using System.Threading.Tasks;
您将需要包括以下内容:

using System;
using System.Threading.Tasks;
例如,

不需要穿线,例如


无需线程处理

根据您使用的内容(WinForms、WPF等),在.NET Framework中有几个计时器实现可用于此目的。指定上下文是否为WinForms/WPF/ASP.NET等?取决于您使用的内容(WinForms、WPF等),.NET Framework中包含多个计时器实现,可用于此目的。请指定上下文是否为WinForms/WPF/ASP.NET等?如果要避免使用额外的方法仅调用原始方法,可以使用lambda函数解决此问题<代码>\u tmr.appeased+=(发送方,参数)=>this.Earning()如果您不想让额外的方法仅仅调用原始方法,可以使用lambda函数来解决这个问题<代码>\u tmr.appeased+=(发送方,参数)=>this.Earning()thnx Appricate for answer.thnx Appricate for answer。