マルチチャイルド アプリケーションを作成しました。アプリケーション ウィンドウ (W[n]: TMyWindows) はすべて同じで、すべてにプライベート オブジェクト クラス インスタンスが関連付けられています (E: TMyObject)。子ウィンドウは、このオブジェクトを通じていくつかのメッセージを生成します。メッセージの内容に応じてこれらのメッセージを処理する 2 つのスレッドをメイン アプリケーションに作成しました。たとえば、次の非同期呼び出しがあります。
W[1].E.Service(thread1service)
W[2].E.Service(thread2service)
TMyObject.Service(servicetype) は
case servicetype of
thread1service: PostThreadMessage(thread1id,...);
thread2service: PostThreadMessage(thread2id,...);
end;
さて、各スレッドの実行メソッドには、次のようなものがあります。
while not terminated do
begin
...
if peekmessage(msg,0,thread1message_1,thread1message_n,pm_remove) then
process message
do other things;
end
2番目のスレッドがメッセージを受信しないことを除いて、すべてうまくいきます。理由はわかりますか?