c# - 在 C# 中由多个线程调用的内部方法创建的数据表是否需要锁定?
问题描述
我有这个下面的方法,在当前方法中创建的数据表,我会将这 4 个数据表发送到 sql 过程,它根据一些验证返回真/假。
怀疑:对于单线程应用程序,它的工作正常。将来我们计划实现任务,以便多个任务可以调用此方法,这种编写方法的方式是否适合多个线程,或者我是否需要实现“锁定”。
我的理解:
这些表不被多个线程共享,每个线程都有自己的数据表,因为这些数据表是在当前方法中实例化的,所以在向数据表添加列时不需要实现锁。我理解正确的方法吗?
private static bool ValidateContent()
{
DataTable bomdata = DataTables.GetChangeDataTable();
DataTable rateupdata = DataTables.GetChangeDataTable();
DataTable domaintabledata = DataTables.GetChangeDataTable();
DataTable algo = DataTables.GetChangeDataTable();
_pvCircularInfo.CircularInfo.ForEach(x =>
{
x.CircularDetails.Algorithms.ForEach(a => {
bomdata.Columns.add(/*adds stmg here to data table*/);
});
x.CircularDetails.FormsInfo.risks.ForEach(a => {
bomdata.Columns.add(/*adds stmg here to data table*/);
});
x.CircularDetails.FormRules.ForEach(a => {
bomdata.Columns.add(/*adds stmg here to data table*/);
});
x.CircularDetails.Lookuptables.ForEach(a => {
bomdata.Columns.add(/*adds stmg here to data table*/);
});
x.CircularDetails.DomainTables.ForEach(a => {
bomdata.Columns.add(/*adds stmg here to data table*/);
});
});
calls the db proc by sending all 4 data tables thast returns true or false
return false/false;
}
解决方案
推荐阅读
- flutter - flutter platformview无法在potrait模式下设置videoview
- performance - 性能问题 - 使用 Nuxt.js 显示动态 HTML 表格
- python - 有没有办法使用 ftplib 找到 FTP 服务器中的剩余空间?
- java - 每当在 CMD/Shell 中运行“java”命令时都会附加未知输出
- python - 用于 gcs-connector 访问谷歌存储的 Spark 提交选项
- c# - 使用 Word.Interop 将页码添加到范围
- r - R通过多个组计算一个变量的平均值而不删除重复项
- python - 指定队列名称时芹菜不消耗任务
- nltk - 实体链接和识别
- python-3.x - 我的程序有时有效,有时无效