简体   繁体   English

实时更新Winforms中的文本字段消息

[英]Realtime updating textfield messages in winforms

I have a service that add items to a class and then serialize a class into a file. 我有一项服务,可以将项目添加到类中,然后将类序列化为文件。

Then I need to create a simple form C# with a textfield (multiline) showing realtime from the deserialized file. 然后,我需要使用文本字段(多行)创建一个简单的C#表单,以显示反序列化文件中的实时信息。

I will have timer every second that will read my List of a property of the class and show it in a textfield. 我将每秒有一个计时器,该计时器将读取我的类的属性列表并将其显示在文本字段中。

My question here is: 我的问题是:

Is there a way that instead of reading again and again the file I can just get the latest rows added and just append to the textfield? 有没有一种方法可以代替我一次又一次地读取文件,而只需添加最新行并将其追加到文本字段中?

var file = File.OpenRead("abc.txt");
file.Seek(1000, SeekOrigin.Begin);

Reading a file, use "Seek" to skip old data. 读取文件时,请使用“搜索”跳过旧数据。

just a suggestion: 只是一个建议:

I think, you should rather use some sort of message queue for this purpose. 我认为,您应该为此目的使用某种消息队列。

Again per your post, instead of directly fetching from file, it would be good if you rather store the deserialized content in a stack . 再次按照您的帖子,而不是直接从文件获取,如果您宁愿将反序列化的内容存储在stack ,那将是很好的。 That way, you can always get the content from top of the stack. 这样,您始终可以从堆栈顶部获取内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM