带定时器的Web服务 [英] Webservice with a Timer
本文介绍了带定时器的Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我有一个问题,希望有人能回答。可以创建一个将数据加载到内存中并使用带有该数据的计时器的Web服务吗?您看到我创建了一个程序,该程序每五秒从一个文件读取一次,并在这五秒钟后显示文件中的数据,但现在我想将其转换为Web服务。这可能吗?如果这是一个愚蠢的问题,我真诚地道歉
Hello,
I have a question I hope someone can answer. It is possible to create a webservice that loads data into memory and use a timer with that data? You see I created a program that reads from a file every five seconds and displays the data within the file after those five seconds but now I want to turn this into a webservice. Is this possible? If this is a stupid question I sincerely apologise
推荐答案
是的,这是可以实现的,你可以创建一个Web服务,从文件中读取数据并存储在变量/模型中。
- timer_tick方法将执行代码来读取文件内容并将内容存储在静态变量中。
- 调用Web服务方法时,返回静态变量的内容。
注意,Web服务不是这是编写计时器代码的好地方。如果每5秒执行一次代码,最好的办法是使用带有定时器执行代码5s的Windows服务(读取文件);文件的内容可以保存在数据存储(SQL Server)中,Web服务只读取数据存储中的最新数据。
Hi,
Yes this is achievable, you could create a web service that reads the data from the file and stores in variable(s)/Model.
- The timer_tick method would execute code to read the file contents and store the contents in a static variable.
- When the web service method is is invoked, you return the contents of the static variable.
Note, the web service isn't a good place to code a timer. If there's code to execute every 5 seconds, your best bet is to go with a Windows service with a Timer executing your code 5s(Read the file); the contents of the file can be saved in a Data store(SQL Server) and the Web service would just read the latest data from the Data Store.
这篇关于带定时器的Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文