3
定时器ASP.NET核心之前,我用来实现这样的计时器:如何实现与.NETCoreApp1.1
public class Class1
{
Timer tm = null;
public Class1()
{
this.tm.Elapsed += new ElapsedEventHandler(Timer_Elapsed);
this.tm.AutoReset = true;
this.tm = new Timer(60000);
}
protected void Timer_Elapsed(object sender, ElapsedEventArgs e)
{
this.tm.Stop();
try
{
// My business logic here
}
catch (Exception)
{
throw;
}
finally
{
this.tm.Start();
}
}
}
我有一个.NETCoreApp1.1控制台应用程序和系统同样需要。使用ASP.NET Core的定时器不再存在。我也尝试使用System.Threading.Timer,但该项目不再构建。
我该如何使用.NETCoreApp1.1实现Timer?有没有相当于System.Timers?
System.Threading.Timer不支持.NET的核心> = 1.1.0请参阅相关性[第(https://www.nuget.org/ packages/System.Threading.Timer /) – Sanket
@Sanket它是兼容的,但我必须添加一个依赖到Microsoft.NETCore.App框架部分 – AdrienTorris