我用互斥实现线程同步
我的同步有问题,帮我看下
MYThread := TDPThread.Create(True);
CoInitialize(nil);
CopyMemory(@MYThread.iFramInfo,Pointer(Integer(@SerialQueue.receiveByte)+pos),Endpos-pos+2);
MYThread.FreeOnTerminate := true;
MYThread.Resume ;procedure TDPThread.Execute;
begin
inherited;
Mutex := CreateMutex(nil,False,'NewMutex') ;
WaitForSingleObject(Mutex,INFINITE) ;
for i:= 1 to cardCount do
begin
if ConvertTo(cardByteInfo) then //卡信息转换正确
begin
if cbJoinRecordToDB.Checked then //归并后的记录是否入库
begin
if CardIsExist(cardConvertFormat,DModule.ADOConnection1) then //该卡的信息已存在
UpdateAccess(cardConvertFormat,DModule.ADOConnection1)
else
InsertToAccess(cardConvertFormat,'T_ActCard',DModule.ADOConnection1);
end ;
if cbOrigRecordToDB.Checked then //是否保存原始记录
InsertToAccess(cardConvertFormat,'T_ActCardRecord',DModule.ADOConnection1); //每条记录都入库 if ScbShowCardInfo.Checked then //是否显示卡的信息
tempStr := ShowCardInfo(cardConvertFormat) + tempStr ;
end ;
end ;
ReleaseMutex(Mutex) ;
CloseHandle(Mutex) ;
end;
现在是: 第一帧,卡A,B,C ; 第二帧,卡A,D,F ;数据库中可能会出现两条A 的记录,应该只有一条,第二次的会更新第一次的
我的同步有问题,帮我看下
MYThread := TDPThread.Create(True);
CoInitialize(nil);
CopyMemory(@MYThread.iFramInfo,Pointer(Integer(@SerialQueue.receiveByte)+pos),Endpos-pos+2);
MYThread.FreeOnTerminate := true;
MYThread.Resume ;procedure TDPThread.Execute;
begin
inherited;
Mutex := CreateMutex(nil,False,'NewMutex') ;
WaitForSingleObject(Mutex,INFINITE) ;
for i:= 1 to cardCount do
begin
if ConvertTo(cardByteInfo) then //卡信息转换正确
begin
if cbJoinRecordToDB.Checked then //归并后的记录是否入库
begin
if CardIsExist(cardConvertFormat,DModule.ADOConnection1) then //该卡的信息已存在
UpdateAccess(cardConvertFormat,DModule.ADOConnection1)
else
InsertToAccess(cardConvertFormat,'T_ActCard',DModule.ADOConnection1);
end ;
if cbOrigRecordToDB.Checked then //是否保存原始记录
InsertToAccess(cardConvertFormat,'T_ActCardRecord',DModule.ADOConnection1); //每条记录都入库 if ScbShowCardInfo.Checked then //是否显示卡的信息
tempStr := ShowCardInfo(cardConvertFormat) + tempStr ;
end ;
end ;
ReleaseMutex(Mutex) ;
CloseHandle(Mutex) ;
end;
现在是: 第一帧,卡A,B,C ; 第二帧,卡A,D,F ;数据库中可能会出现两条A 的记录,应该只有一条,第二次的会更新第一次的
解决方案 »
- 中国象棋(如何检测出棋面上走了一步棋后,一方将是否正在被对方的炮将军)
- dll的问题,大伙帮帮我
- 各位大哥快帮我看看呀
- 关于‘DateTimePicker’控件的使用
- 如何将edit.text中的字符串转换为一个二进制数组,谢谢!!!!!
- 同一個系統,在win98和win2000下quickReport中文字顯示不一樣。如下:
- 再问问大家!谢谢帮助,
- 如何在其它事件中调ListrView的ListView1CustomDrawItem事件!!!!
- 这是什么原因啊?谁能帮我解答一下(数据库方面的)
- 帮帮我!!!!!!
- 有人用过inno setup吗
- 求救~~有没有方法让ADODataSet.SaveToFile来保存MYSQL查询后的结果。
加个限制的全局变量好象可以啊