程序流程 - 实现程序的正确方法 [英] Program Flow - The correct way to implement my program

查看:119
本文介绍了程序流程 - 实现程序的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须用C#编写一个程序,我必须学习,我通过虚拟串口接收数据并实时在图表上显示结果。图表需要有一个滑块,以便我们可以查看数据的历史记录。



我正在考虑如何实现这一点并考虑以下内容。< br $>


1)主要流程:Windows,按钮,GUI等。

2)用于串行通信的独立线程。读取和写入数据块,一些数据包将是实时的,因此将被转移到数组或外部数据库。

3)另一个线程将从数组/数据库中获取数据并更新实时图形。



如果所有这些都在一个进程/线程中实现,那么它肯定会在某个时刻停止程序执行。



C#是一个很好/不同/奇怪的语言,可以在C / Assembler编程后掌握,所以任何帮助都会受到赞赏。



谢谢

I have to write a program in C#, which I have to learn, in which I receive data over a virtual serial port and display the results on a graph in real time. The graph needs to have a slider so that we can look at the history of the data.

I was thinking on how to implement this and thought about the following.

1) Main Process: Windows, buttons, GUI, etc.
2) Separate thread for serial communications. Reading and writing data blocks, some data packets will be real time and so will be transferred to an array or external database.
3) Another thread which will take the data from the array/database and update the graph in real time.

If all of this is implemented in a single process/thread then it will surely halt program execution at some point.

C# is a good/different/weird language to get to grips with after programming in C/Assembler so any help is appreciated.

Thanks

推荐答案

第一个建议:

1)您必须使用多个线程来处理共享资源(数组)锁定例如;

2)UI和逻辑线程之间的通信应该通过使用接口来完成,例如用于显示图形的UI表单应该实现允许加载线程调用RefreshUI的接口()当新数据表示a你可以通过UI表单通知第二个线程更新(新)图表,所以这里还需要第二个接口;
First suggestions:
1)You must take care of accessing the shared resources (arrays) by multiple threads by using locks for example;
2)The communication between UI and logic threads should be done by using interfaces, for example the UI form used for displaying the graphs should implement an interface that allow the loading thread to invoke RefreshUI() when new data that are available, and from the UI form you should notify the 2nd thread for updating the (new) graph, so also here a 2nd interface is needed;


这篇关于程序流程 - 实现程序的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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