调用过程“延迟”的最佳方法是什么? [英] What is the best way to call a procedure "delayed"?

查看:67
本文介绍了调用过程“延迟”的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有两个过程A1和A2,它们都在其代码中调用函数B:

There are two procedures, A1 and A2, which both call function B in their code:

function B: boolean;
begin
  // do other stuff
end;

procedure A1;
begin
  // do stuff
  if b then
    ...
  // do stuff
end;

procedure A2;
begin
  // do stuff
  if b then
    A1; // <- how to call A1 "delayed"?
  // do stuff
end;

如果A2中的条件为true,则必须调用过程A1,但是当A2为

If the condition in A2 is true, procedure A1 must be called, but that would happen while A2 is still running, which I don't want.

应该发生的情况是:
如果A2中的条件为true,则A2应该完成并离开A2应该调用过程A1。

What should happen is: If the condition in A2 is true, then A2 should be finished and after leaving A2 the procedure A1 should be called.

一个丑陋的解决方案是设置一个在确保A2完成的延迟后调用A1的计时器。

An ugly solution would be to set a timer that calls A1 after a delay that makes sure A2 is finished.

但是必须有更好的方法,对吧?

But there must be better ways, right?

编辑:对于我来说,A1和A2是事件,因此它们不会被代码调用,并且我不能仅在A2完成后从调用过程中调用A1。

EDIT: A1 and A2 in my case are events, so they are not called by code and I cannot just call A1 from a calling procedure after A2 is finished.

推荐答案

给出您的约束听起来像您想在返回之前调用 PostMessage 作为 A2 中的最后一个东西。应该设置 PostMessage 参数,以便触发 A1 事件。唯一需要担心的是竞争状况,但我不确定Windows消息队列是否会成为问题。

Given your constraints it sounds like you want to call PostMessage as the last thing in A2 before returning. The PostMessage parameters should be set up so trigger the A1 event. The only thing to worry about it a race condition, but I'm not sure that'll be an issue with the windows message queue.

这篇关于调用过程“延迟”的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆