C#4.0 - 在一个区间线程 [英] C# 4.0 - Threads on an Interval

查看:202
本文介绍了C#4.0 - 在一个区间线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C#4.0。我的代码,我想每一个执行2-3分钟块。什么是可用的4.0线程功能来做到这一点的正确方法?

I'm using C# 4.0. I have a block of code I would like to execute every 2-3 minutes. What is the correct way to do this with the 4.0 threading features available?

推荐答案

使用System.Threading.Timer。

Use System.Threading.Timer.

new Timer(TimerTick,null,TimeSpan.Zero,TimeSpan.FromMinutes(2));

private void TimerTick(object obj)
{
    Thread myThread =  new Thread(() => {});
    myThread.Start();
}

这篇关于C#4.0 - 在一个区间线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆