我将 Indy 9 与 Delphi 5 一起使用。在我的应用程序中,我想通过 UDP 与网络设备通信。所以我使用UDPServer comp。在从 TThread 派生的类中。当我编写类似于以下代码时,CPU 使用率为 100%。
在线程中:
while not terminated do begin
if GetMessage(Msg, 0, 0, 0) then begin
if Msg.message = WM_UDPMSG then
Break
else
DispatchMessage(Msg);
end;
end;
和 OnUDPRead 事件:
try
// Processing the data here
except
PostThreadMessage(ThreadId, WM_UDPMSG, 0, 0);
end;
当我在 while-do 循环或 OnUDPRead 事件中使用睡眠功能时,没有任何变化。CPU使用率仍然是100%。
我的线程优先级是正常的。
我该如何解决我的问题?