可以将数据存储在作为计划任务运行的控制台应用程序中吗? [英] Possible to store data in a console application run as a scheduled tasks?

查看:72
本文介绍了可以将数据存储在作为计划任务运行的控制台应用程序中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我已经实现了一个控制台应用程序,它根据Web服务返回的数据发送邮件。我已将其配置为每5分钟运行一次的Windows任务调度程序。



这里我使用该服务检索员工状态列表。员工状态可以是活动状态,非活动状态,也可以是其他人。每当发生以下状态更改时,我都必须向员工电子邮件ID发送通知邮件,Active-> Inactive和Inactive-> Active。所以简而言之,这需要我存储以前的状态。



有没有办法存储以前的数据..请提供建议。



谢谢



我尝试了什么:



我尝试使用静态变量。但我相信,因为应用程序每5分钟运行一次,它就作为一个新的应用程序启动

Hi,

I have implemented a console application that sends a mail based on the data returned from a web service. I have configured it as a windows task scheduler that runs every 5 mints.

Here I am retrieving a list of employee status using the service. Employee status can be Active, Inactive and few others too. I have to send a notification mail to the employee email id whenever the following status change occurs, "Active-> Inactive" and "Inactive->Active". So in short this requires me to store the previous status.

Is there any way to store the previous data.. Kindly advice.

Thanks

What I have tried:

I tried using static variable. But I believe since the application is run each 5 mints, it starts as a new application

推荐答案

如果任务每次运行都是新的,那么任何内存变量都会在以前的运行不存在。您需要使用永久存储,即磁盘文件。或者,您可以使用一个应用程序的单个实例,该实例使用计时器每五分钟运行一次。通过这种方式,你可以将所有信息保存在内存中。
If the task runs as new each time then any memory variables used in the previous run do not exist. You need to use permanent storage, i.e. a disk file. Alternatively you could have a single instance of the application that uses a timer to run every five minutes. In that way you could keep all the information in memory.


我同意理查德:如果这是一个每隔几分钟发布的新应用程序,那么你需要在应用程序外部永久存储 - 但是我建议数据库可能比磁盘文件更好,因为它们组织得更好,在添加,删除或更改数据时需要更少思考。

看看这里:演练:将数据保存到数据库(单表) [ ^ ]当你绕过它时,它并不复杂,这是值得了解的东西!
I agree with Richard: if this is a new app firing every few minutes, then you will need permanent storage outside the app - but I'd suggest that a Database might be better than a disk file, as they are better organised and require less "thinking about" when it comes to adding, removing, or changing data.
Have a look here: Walkthrough: Saving Data to a Database (Single Table)[^] it's not that complicated when you get your head round it, and it's stuff that it's well worth knowing!


这篇关于可以将数据存储在作为计划任务运行的控制台应用程序中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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