网站建设资讯

NEWS

网站建设资讯

c#之下如何做定时-创新互联

先如下定义一个定时器:

公司主营业务:成都网站设计、成都做网站、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。成都创新互联是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。成都创新互联推出扶沟免费做网站回馈大家。

public DispatcherTimer dispatcherTimer;

然后在某处创建这个对象实例:

dispatcherTimer = new System.Windows.Threading.DispatcherTimer();

设定超时回调函数:

dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);

设定间隔(下方例子是10秒钟):

dispatcherTimer.Interval = new TimeSpan(0, 0, 10);

启动定时器:

dispatcherTimer.Start();

定义超时回调函数:

private void dispatcherTimer_Tick(object sender, EventArgs e)

{

// do something here...

}

值得注意的是DispatcherTimer是无法直接在console下运行的,需要额外的东西。

下面文字来自http://stackoverflow.com/questions/19351473/dispatchertimer-doesnt-work-in-console的解释

The console and unit test environment by default don't have a dispatcher to run your dispatcher timer.

You can still use Dispatcher.CurrentDispatcher to create a Dispatcher to run your code.

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网站名称:c#之下如何做定时-创新互联
分享URL:http://cdweb.net/article/diigej.html