使程序无限期等待直到参数使它在给定的时间点进行处理的最佳方法 [英] best way to make a program wait indefinitely until a parameter makes it process somehting at a given point in time

查看:86
本文介绍了使程序无限期等待直到参数使它在给定的时间点进行处理的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,谢谢您阅读本文.

该程序的目的是不时检查数据库,直到特定参数说要在特定日期/时间处理练习,当该时间到来时,程序开始处理其应有的内容并用更新数据库结果.它将再次等待,直到另一个用户在给定的时间点提供了另一份要处理的内容

我想知道启动此应用程序的最佳方法是什么

我可以永远使用一会儿或for(;;)或其他一些无休止的循环,但我不认为这是明智的.

我也不知道它将如何给出状态消息,如等待或处理.还有一个强制过程和一个击杀等待或以一种健康的方式终止它的事情将是非常好的

我也不想使这个应用程序变得非常复杂

如果你们可以引导我写一篇文章或给我提示要寻找的内容,我会非常感激,因为我根本找不到适合的文档来阅读,也许我使用的是错误的关键字或其他内容

再次感谢您的宝贵时间.

Hello and thanks in advance for reading this.

the purpose of this program is to check the database from time to time until a specific parameter says the excersice is to be processed on a specific date/time, when that time arrives the program starts to process what its supposed to and updates the database with the results. it will wait again until another user gives another excersice to process in a given point in time

i am wondering what would be the best aproach to begin this app

i could use a while forever or a for(;;) or some other un-ending loop but i dont think that would be wise.

also i dont know how it will give a status message like waiting or processing. also it would be very good to have a force process and a kill wait or something that terminates it the healthy way

i dont want to make this app very complicated either

if you guys could lead me to an article or give me a hint of what to look for i would apreciate it very much because i simply cannot find apropiate documentation to read, maybe i am using wrong keywords or something

thanks again for your time

推荐答案

永远或永远没有尽头是不明智的.

为什么不放入计时器?将其设置为适当的时间间隔,并在发生Tick事件时,检查数据库.
这样一来,您大部分时间就什么都不做.
您可以使用一个UI来表明自己还没死,而对系统的负担却很小.
如果需要,甚至可以将其设置为Windows服务.


"尽管如此,但是问题在于,应该每天像一次那样处理练习,或者类似的事情.这个应用程序也应该在没有监视的情况下工作,这意味着家伙离开了工作回家,可以去检查一下第二天或其他时间."


设置一个每分钟触发一次的计时器(例如).
设置您希望进行下一次检查的时间:从现在开始说12个小时,作为一个班级DateTime:
While forever or unending for is not wise.

Why not put in a timer? Set it for a suitable interval, and when the Tick event happens, check the DB.
That way, you are doing nothing at all most of the time.
You can have a UI to show that you aren''t dead, with minimal load on the system.
Even make it a Windows Service if you want.


"also though of that but problem is the excersices are supposed to be processed like once a day or something like that. also this app is supposed to work unwatched meanin the guy leaves it working and go home, to come and check it the next day or some other time."


Set up a Timer that fires every minute (say).
Set up a time when you want the next check to take place: say 12 hours from now, as a class level DateTime:
private DateTime nextCheck;
private SetNextCheck()
   {
   nextCheck = DateTime.Now.AddHours(12);
   }


在您的计时器滴答事件中检查是否是时间:


In your timer tick event check if it is time:

if (DateTime.Now > nextCheck)
   {
   SetNextCheck();
   DoNewCheck();
   }

您可能希望获得比这更微妙的信息:在一个小时而不是仅仅12小时前,但是您有了基本的想法.

You might want to get a little more subtle than that: on the hour rather than just 12 hours forward, but you get the basic idea.


我不确定问题出在哪里是.因此,默认情况下,您对数据库不执行任何操作.然后,您等待此参数被设置.我假设用户通过UI进行设置,然后UI在类上设置属性.因此,从属性设置器中,您可以轻松触发OnPropertyNameChanged ,然后可以触发事件(例如DatabaseUpdateRequested),并且您具有处理此事件的代码.在事件处理程序中,您需要执行数据库更新任务.触发事件后,该属性应将其自身重置为正常状态.

根据对您发布内容的理解,我已经回答了您.如果您需要更多相关信息,请通过评论回复(但不要发布新的答案).
I am not sure where the problem is. So by default you don''t do anything to the database. Then you wait for this parameter to be set. I assume the user sets it via the UI, and the UI then sets a property on a class. So from the property setter you can easily fire an OnPropertyNameChanged and then this can fire an event (example DatabaseUpdateRequested) and you have code that handles this event. In the event handler you do the required database update tasks. Once the event has been fired, the property should reset itself back to the normal state.

I''ve answered you based on my understanding of what you posted. If you need more info on this, please respond back via comments (but do not post a fresh new answer).


这篇关于使程序无限期等待直到参数使它在给定的时间点进行处理的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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