在C#中使数据集线程安全 [英] Making datasets thread safe in C#

查看:81
本文介绍了在C#中使数据集线程安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使数据集在写入时具有线程安全性的最佳模式是什么?

What's the best pattern for making datasets threadsafe on write?

通过谷歌搜索可以找到的最好的方法是'实现带锁的包装层',但乍一看这看起来很杂乱。

The best I can find by googling is 'implement a wrapper layer with locks' but at first blush this seems rather messy.

有人可以推荐/指出我一个好的解决方案的方向吗?

Can someone recommend / point me in the direction of a good solution to this? It seems likely to be a problem that has already been solved somewhere.

编辑:我还需要将数据集绑定到ui网格,这使事情变得有些复杂。

edit: I also need to bind the dataset to a ui grid, which complicates matters somewhat.

推荐答案

用锁实现包装层是解决方法。

"Implement a wrapper layer with locks" is the way to go.

包装层可能会使用特定于应用程序使用数据集方式的锁定。

The wrapper layer will likely use locking that is specific to the way your application uses the DataSets.

尝试为像DataSet这样复杂的类设计通用解决方案

Attempting to design a generic solution for a class as complex as a DataSet is probably doomed to failure.

例如,枚举属性通常不是线程安全的-因此,只要任何调用者枚举,您都需要持有一个锁许多集合属性中的任何一个(DataSet.Tables,DataTable.Rows等)。

For example, enumerating properties will generally not be thread-safe - so you would need to hold a lock for as long as any caller is enumerating any of the many collection properties (DataSet.Tables, DataTable.Rows, ...).

这篇关于在C#中使数据集线程安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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