我如何使用计时器作为数组 [英] How do I use timers as arrays

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

问题描述

所以我在Windows窗体应用程序中为MEWS系统制作了一个程序,该程序显示患者的医院生命体征.我使用计时器来显示彩色条,以显示生命体征水平.我想知道的是,每次运行程序时,如何使用数组存储计时器编号结果,因此我可以将结果存储在集合组件中.

Hi, so I made a program in a windows form application for a MEWS System which displays patients vital signs for a hospital. I used timers to display coloured bars to show the vital sign levels. what I want to know is how can i use arrays to store the timer number results each time I run the program, so i can have the results stored in a collection component.

推荐答案

不确定我是否理解您的问题,但我认为您正在问如何使用计时器存储它们从传感器检索的数据值?

首先,计时器是任意计时装置,没有任何数据存储装置.您需要自己实现该层.

接下来,您需要确定需要存储数据的时间.如果您需要这些数据的持续时间长于应用程序重新启动的时间,则需要将数据存储在文件或数据库中.如果只需要临时存储数据,则可以考虑使用Stack< t>.或List t之一变体.

确定持久性介质(SQL Server,XML文件,内存等)后,您需要找出一个模型来存储从输入设备读取的数据.我建议将sensorID,时间戳,sensorvalue存储在表或类对象中,但是您是唯一可以回答该问题的人.

您可能会考虑构建应用程序,以便拥有独立的机制:一种用于读取数据的系统,一种用于持久存储数据的系统,一种用于显示数据的系统以及一种用于控制应用程序的系统.

希望对您有所帮助.
Not sure I understand your question, but I think you''re asking how to use timers to store the data values they are retrieving from the sensors?

To begin, timers are arbitrary time keeping devices without any provisions for data storage. You need to implement that layer yourself.

Next you need to determine how long you need to store the data for. If you need this data to persist longer than an application restart then you''ll need to store the data in a file or in a database. If you only need to store the data temporarily, you could consider using a Stack<t> or one of the List<t> variants.

After you determine your persistence medium (SQL Server, XML file, Memory, etc) you''ll need to figure out a model to use to store the data as it is read from the input device. I would suggest storing the sensorID, timestamp, sensorvalue within a table or class object but you''re the only one who can answer that question.

You may consider building your app so that you have separate mechanisms: one system for reading the data, one system for persisting it, one system for displaying it and one system for controlling the application.

Hope that helps you.


为什么要使用计时器数组?最好为不同的处理创建类,然后让那些类决定是否必须完成工作.

计时器事件时发生(基于最短的时间范围,例如100 ms.):
Why use an array of timers? It would be better to create classes for different processing and let those decide if work must be done.

on timer event (based on the shortest time span, for example 100 ms.):
vital1.execute;
vital2.execute;
vital3.execute;



或更好:



or better yet:

foreach(vital in vitals)
{
  vital.execute;
}



例如:关键1每200毫秒执行一次,关键2每100毫秒执行一次,关键3每400毫秒执行一次.

在执行中,您检查时间是否已到期,进行一些处理并将值(用于检查时间是否已到期)设置为以时间间隔(例如200毫秒)递增的当前时间.

您可以使用DateTime.Now + TimeSpan.FromMilliseconds(100);计算下一次检查是否经过了100 ms.

使用此方案,您只需要一个计时器即可安排每个生命周期的处理.请注意,总处理必须超过计时器间隔,否则将意味着处理将落后(因为在开始处理而先前处理甚至没有完全结束的情况下开始处理).

祝你好运!



For example: vital 1 needs to be executed every 200ms, vital 2 every 100ms and vital 3 every 400ms.

In the execute you check if the time has expired, do some processing and set the value (for checking if the time has expired) to the current time incremented with the interval (for example 200 ms.)

You can use DateTime.Now + TimeSpan.FromMilliseconds(100); to calculate the next time to check if 100 ms have elapsed.

Using this scheme you only need a single timer to schedule processing of each vital. Be aware that total processing must nut exceed the timer interval because it would otherwise mean that processing will get behind (because processing is started while previous processing did not even end completely).

Good luck!


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

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