Making datasets thread safe in C#(在 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# 中使数据集线程安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 C# 中使数据集线程安全


基础教程推荐
- JSON.NET 中基于属性的类型解析 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01