我想我要使用计时器吗? [英] I think I want to use a timer?

查看:97
本文介绍了我想我要使用计时器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不使用设计文档的乐趣...这是我作为副项目工作了一段时间(没有到期日")的同一个应用程序,现在我得到了再往前一点,碰到一点障碍.
这是应用程序的基本功能:我需要它登录到邮件服务器,查看其中有多少条消息,从这些消息中获取一些数据并更新数据库.我已经设法使所有工作正常进行,现在解决了这个问题,我需要使用它来运行所有这么小的消息(我认为5?).我尝试使用计时器,但我的后台工作程序不断出现跨线程错误(用于更新表单).我会发布代码,但是我已经删除了它,但是真的不再拥有它了.但是,我所需要的只是将以下内容调用5分钟左右.< cleanUpFiles(); bgwRetreive.RunWorkerAsync();


cleanUpFiles将状态写入文本框,并且使用bgwRetreive中的进度更新进行了大量写入操作.我现在唯一想到的另一件事是让一个循环在线程上运行以检查时间戳,然后在命中时运行代码?尽管我不确定是否会影响资源,因为我必须在无限循环中运行它以等待某种取消?
显然,这是我第一次尝试做这样的事情,因此出现了问题.
预先感谢.

解决方案

This is the basic functionality of the app: I need it to log into a mail server, see how many messages are there, get some data from those messages and update a database. I''ve managed to get all that working and now for the problem, I need this to run every so many minuets (I''m thinking 5?). I''ve tried using a timer and I keep getting cross thread errors on my background workers (used to update the form). I''d post the code, but I kinda deleted it and well don''t really have it any more. However all that I need is for the following to be called ever 5 or so min

cleanUpFiles();
bgwRetreive.RunWorkerAsync();


cleanUpFiles writes the status to a text box, and there are a bunch of writes using the progress updates in bgwRetreive. The only other thing I can think of right now is to have a loop running on a thread checking for a time stamp, and then running the code when it hits it? Though I''m not really sure how that will affect resources as I''d have to run it in an infinite loop waiting for a cancel of some sort?
Obviously this is the first time I''ve tried to do something like this, thus the problems.
Thanks in advance.

解决方案

http://blogs.msdn.com/b/csharpfaq/archive/2004/03/17/91685.aspx[^]


Yup a timer should be good enough for this requirement. So go ahead and use one.
Post here if you face any further issues.


这篇关于我想我要使用计时器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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