我在进行Socket通信时
设置ClientSocket通信方式为ctBlocking
使用一个线程来不断地读取数据信息
procedure TRecThread.Execute;
var command:String;
begin
while (true) do
begin
command := '';
if (CSocket.Socket.ReceiveLength <> 0) then
command := CSocket.Socket.ReceiveText();
if (Length(trim(command)) <> 0) then
parseMessage(command);
sleep(100);
end;
end;
然而,在其他时候,我对CSocket操作的时候,会导致程序不动了,直到CSocket收到一条消息,才会继续运行?在Java中有对对象加锁的方法
synchronized(CSocket){}
这样执行,不知道在Delphi中是如何处理的???
设置ClientSocket通信方式为ctBlocking
使用一个线程来不断地读取数据信息
procedure TRecThread.Execute;
var command:String;
begin
while (true) do
begin
command := '';
if (CSocket.Socket.ReceiveLength <> 0) then
command := CSocket.Socket.ReceiveText();
if (Length(trim(command)) <> 0) then
parseMessage(command);
sleep(100);
end;
end;
然而,在其他时候,我对CSocket操作的时候,会导致程序不动了,直到CSocket收到一条消息,才会继续运行?在Java中有对对象加锁的方法
synchronized(CSocket){}
这样执行,不知道在Delphi中是如何处理的???
解决方案 »
- 求Delphi师父一位
- 更新数据问题.急,在
- clientdataset怎么修改数据?
- 生死存亡!!找工作!!帮顶送分!!
- 如何利用ClientDataSet的commandtext 属性动态查询? 在线等待
- 请教,这是为什么,我在delphi7的Ttreeview中加入几个节点,可出现的是一堆乱字!
- 这个问题好像有人问过,不过还是请大哥帮个忙
- 俺手头有个报表控件,用了N年,做了N多项目(有N大型应用),大家试用一下有合理意见者给高分
- 下了一个控件,请问如何使用?
- TForm.create(self)和TForm.create(application)
- 梦的启事
- 可以不用Object Inspector来设置属性吗?
他使用synchronize方法处理
不知道如何对某个对象同步??
比如
a线程在使用CSocket前,将其加锁,b线程只有等待a线程使用完CSocket,并释放这个锁,他才能使用CSocket.
var command:String;
begin
while (true) do
begin
command := '';
if (CSocket.Socket.ReceiveLength <> 0) then
command := CSocket.Socket.ReceiveText();
if (Length(trim(command)) <> 0) then
parseMessage(command);
sleep(100);
end;
end;改为:
procedure TRecThread.Execute;
begin
synchronize(ReceiveMsg);
end;procedure TRecThread.ReceiveMsg()
var
command:String;
begin
while (true) do
begin
command := '';
if (CSocket.Socket.ReceiveLength <> 0) then
command := CSocket.Socket.ReceiveText();
if (Length(trim(command)) <> 0) then
parseMessage(command);
sleep(100);
end;
end;
< 不知道如何对某个对象同步??
< 比如
< a线程在使用CSocket前,将其加锁,b线程只有等待a线程使用完CSocket,并释放这个锁,他才< 能使用CSocket.如果一定要同步的话。
你可以使用API的临界对象(或者信号对象)啊?