程序根据时间间隔检查任务。 [英] Program to check a task based on time interval.

查看:63
本文介绍了程序根据时间间隔检查任务。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我试图找出Windows服务应用程序的最佳替代方案。我有一些任务要根据时间间隔连续执行。



我不想使用Windows安装程序或不创建单独的线程来实现它。



请建议一些最好的方法来实现这个...



我的实际要求是我使用的是RabbitMQ用于消息传输。它有发送和接收队列。持续接收队列以进行监视,以检查队列中消息的可用性。为此我需要写一些像windows服务组件的东西。



请建议一些最好的方法,以便我可以持续监控接收消息队列。



谢谢

解决方案

所以:No Service&没有额外的线程?



投票:



 DateTime _time = DateTime 。现在; 
...


private void MessagePoll ( int intervalSeconds){

Timespan timespan = Timespan.FromSeconds(intervalSeconds)

// 无限线程。没有第二个帖子就无法阻止
true ){
// 如果尚未达到时间间隔 - 等待
while (DateTime.Now-_time < timespan){
Thread.Sleep( 1000 );
}
// 做好工作
PollMessages();
重置时间。
_time = DateTime.Now;
}

}







你也可以使用 Thread.sleep代码(intervalSeconds * 1000)


Hi,

I am trying to find out the best alternative to windows service application. i have some task to be executed continuously based on time interval.

I don't want to go with windows installer or not to create separate thread to achieve it.

Please suggest some best approach to achieve this...

my actual requirement is i am using RabbitMQ for message transmission. it has send and receive queues. Receive queue continuously to be monitored for checking the availability of messages in the queue. for this i need to write some thing like windows service component.

Please suggest some best approach so that i can monitor Receive Message Queue continuously.

Thanks

解决方案

so: No Service & no extra threads?

Polling:

DateTime _time = DateTime.Now;
...


private void MessagePoll(int intervalSeconds){

 Timespan timespan = Timespan.FromSeconds(intervalSeconds)

 //infinite thread.  You have no way to stop this without a second thread
 while(true){
  //If the time interval has not been reached - wait
  while(DateTime.Now-_time < timespan ){
   Thread.Sleep(1000);
  }
  //Do the work
  PollMessages();
  reset the time.
  _time = DateTime.Now;
 }

}




You can also just use Thread.Sleep(intervalSeconds*1000)


这篇关于程序根据时间间隔检查任务。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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