static DataTable Cache;
.....
public static DataRow GetRow(string deviceId)
{
lock (Cache)
{
if (Cache.Rows.Count == 0) return null;
string filter = string.Format("(Device not like '%{0}%' or Device ='') and Lock = 0", deviceId);
DataRow[] row = Cache.Select(filter, "Priority desc");
if (row == null || row.Length == 0) return null;
if (row[0]["Lock"].Equals(0))
{
row[0]["Lock"] = 1;
return row[0];
}
return null;
}
}....
SendMessage(DataRow row)
{....只取数据处理,数据库操作...}
两个线程调用静态方法GetData,取Cache中一条数据处理(每条数据只能被一个线程处理)运行程序,发现两个线程处理同一条数据的问题,求解决方案?
.....
public static DataRow GetRow(string deviceId)
{
lock (Cache)
{
if (Cache.Rows.Count == 0) return null;
string filter = string.Format("(Device not like '%{0}%' or Device ='') and Lock = 0", deviceId);
DataRow[] row = Cache.Select(filter, "Priority desc");
if (row == null || row.Length == 0) return null;
if (row[0]["Lock"].Equals(0))
{
row[0]["Lock"] = 1;
return row[0];
}
return null;
}
}....
SendMessage(DataRow row)
{....只取数据处理,数据库操作...}
两个线程调用静态方法GetData,取Cache中一条数据处理(每条数据只能被一个线程处理)运行程序,发现两个线程处理同一条数据的问题,求解决方案?
解决方案 »
- C# 中鼠标左键点击 右键菜单之外的地方,右键菜单消失,如何实现!?
- 就3句代码,怎么弄都不行,关于Decimal
- 两批数据对比的算法
- 急,急,急,懂利用WMI接口控制虚拟机的进。。。帮帮小弟
- XML转换问题,新手上路,急!!!
- VB的汉字拼音的首字符的获取源码请译成C#的。
- 请教一个C#使用WebClient中DownloadFile方法问题
- 高分求DeKlarit的使用说明和教程!
- 一个超高难度的问题,如果有满意的答案还可加分
- 如何将C#编写的windows应用程序运行再非.net平台上?
- BackgroundWorker还能提示不能访问另一个线程的控件
- XmlException 帮忙解决一下
"(Device not like '%{0}%' or Device ='') and Lock = 0"
问题是,我不对row进行edit操作
lock(Cache) 是否保证每次只能有一个线程进入方法体取row