保存并读回存储的秒表对象 [英] Save and read back stored Stopwatch object

查看:56
本文介绍了保存并读回存储的秒表对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我需要将System.Diagnostics.Stopwatch存储在数据库中.

我设法将其存储为blob(byte),并且可以将其读回为字节,但是后来我无法将其转换回System.Diagnostics.Stopwatch对象.

有谁可以帮助您?

我认为真正的问题是如何将字节返回秒表对象.

衷心的问候

Heino

Hello

I need to store the System.Diagnostics.Stopwatch in database.

I managed to store it (as blob(byte)) and i can read it back as byte, but then i have problem to convert it back to the System.Diagnostics.Stopwatch object.

Any one that can help ?

I think the real issue is how to get the bytes back to the stopwatch object.

With Kind Regards

Heino

推荐答案

尝试类似的方法:

Try something like this:

Stopwatch stopWatch = (StopWatch)DataTable.Rows[0]["StopWatch"];



编辑(评论后)============

让我问你一个问题-为什么只需要一个或两个属性时为什么要保存整个对象?您不能只是将数据库中的列从blob更改为bigint并使其更容易使用吗?实际上,您真正需要的只是ElapsedTicks属性,而您应该是黄金.



EDIT (after comment) ===========

Let me ask you this - why are you trying to save an entire object when you only need one or two properties? Can''t you just change the column from a blob to a bigint in your db and make it easier on yourself? In fact, all you really need is the ElapsedTicks property, and you should be gold.


您的问题有两个.首先,约翰是对的,像这样存储对象是愚蠢的.如果您的UI层更改了如何显示此数据怎么办?您唯一需要的数据就是刻度线.但是,如果您使用序列化来获取对象的字节表示,则需要反转该过程以从字节流中构建对象.如果您不这样做,那么我怀疑您数据库中的数据首先是秒表对象.
Your issue is two fold. First, John is right, storing an object like this is stupidity. What if your UI layer changes how it shows this data ? The only data you need, is the ticks. However, if you have used serialisation to get a byte presentation of the object, then you need to reverse that process to build the object out of the stream of bytes. If you didn''t do that, I doubt the data you have in your DB represents a stopwatch object in the first place.


这篇关于保存并读回存储的秒表对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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