C# 控制台定时器
- 作者: 守护么么哒
- 来源: 51数据库
- 2021-07-28
c# 定时器
关于c#中timer类 在c#里关于定时器类就有3个
1.定义在system.windows.forms里
2.定义在system.threading.timer类里
3.定义在system.timers.timer类里
system.windows.forms.timer是应用于winform中的,他是通过windows消息机制实现的,类似于vb或delphi中的timer控件,内部使用api settimer实现的。他的主要缺点是计时不精确,而且必须有消息循环,console application(控制台应用程式)无法使用。
system.timers.timer和system.threading.timer很类似,他们是通过.net thread pool实现的,轻量,计时精确,对应用程式、消息没有特别的需要。system.timers.timer还能够应用于winform,完全取代上面的timer控件。他们的缺点是不支持直接的拖放,需要手工编码。关于c#中timer类 在c#里关于定时器类就有3个
1.定义在system.windows.forms里
2.定义在system.threading.timer类里
3.定义在system.timers.timer类里
system.windows.forms.timer是应用于winform中的,他是通过windows消息机制实现的,类似于vb或delphi中的timer控件,内部使用api settimer实现的。他的主要缺点是计时不精确,而且必须有消息循环,console application(控制台应用程式)无法使用。
system.timers.timer和system.threading.timer很类似,他们是通过.net thread pool实现的,轻量,计时精确,对应用程式、消息没有特别的需要。system.timers.timer还能够应用于winform,完全取代上面的timer控件。他们的缺点是不支持直接的拖放,需要手工编码。
private void load()
{
system.timers.timer atimer = new system.timers.timer();
atimer.elapsed += new elapsedeventhandler(theout); //到达时间的时候执行事件;
// 设置引发时间的时间间隔 此处设置为1秒(1000毫秒)
atimer.interval = 100000;
atimer.autoreset = true;//设置是执行一次(false)还是一直执行(true);
atimer.enabled = true; //是否执行system.timers.timer.elapsed事件;
}
public void theout(object source, system.timers.elapsedeventargs e)
{
arraylist autotask = new arraylist();
autotask.add("8:30:00");
autotask.add("9:30:00");
autotask.add("10:30:00");
autotask.add("11:34:15");
for (int n = 0; n < 4; n++)
{
if (datetime.now.tolongtimestring().equals(autotask[n]))
{
messagebox.show("现在时间是" + autotask[n]);
}
}
}
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源
