ShellExecute执行前等待? [英] Wait before ShellExecute is carried out?

查看:774
本文介绍了ShellExecute执行前等待?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有希望的快速问题:有可能延迟执行ShellExecute一点点吗?



我有一个自动更新的应用程序。它下载所有必要的文件等后,将当前文件重命名为* .OLD和新的。足够简单但是,我需要删除那些.OLD文件。这个'清理'过程在MainForm.OnActivate中执行(检查是否是第一个activate proc)。但这显然发生得太快了(我从DeleteFile得到False)。这是程序:

  procedure TUpdateForm.OKBtnClick(Sender:TObject); 
const SHELL ='ping 127.0.0.1 -n 2';
begin
ShellExecute(0,'open',pchar(SHELL +#13 + Application.ExeName),nil,nil,SW_SHOWNORMAL);
Application.Terminate;
结束

此过程应该重新启动应用程序。我确定删除问题是由于第二个应用程序的快速启动引起的,因为如果我自己重新启动,给它一点时间,文件将被正常删除。



tl; dr 版本:我需要调用ShellExecute()等待一点(0.1秒左右),然后执行命令。



注意



我尝试使用-ping命令来尝试延迟它,但没有



非常感谢您提前



编辑:转载 p>

我需要这样做||第一个应用程序关闭;等待100 ms;第二个应用程序打开 ||。我需要首先调用ShellExecute,然后等待调用应用程序完全关闭,然后执行shell(即打开第二个应用程序)

解决方案

p>你正在做一个autopatcher权利?



我遇到了同样的问题,这就是我绕过它:



您使用参数--delay运行第二个应用程序或类似的东西。
第二个应用程序处理参数--delay,睡眠100 ms,然后继续正常运行。


I have a hopefully quick question: Is it possible to delay execution of ShellExecute a little bit?

I have an application with autoupdater. After it downloads all necessary files etc, it renames current files to *.OLD and the new as the previous. Simple enough. But then I need to delete those .OLD files. This 'cleanup' procedure is executed on MainForm.OnActivate (with a check if it is the first activate proc). But this apparently happens too fast (I get False from DeleteFile). This is the procedure:

procedure TUpdateForm.OKBtnClick(Sender: TObject);
const SHELL = 'ping 127.0.0.1 -n 2';
begin
  ShellExecute(0,'open',pchar(SHELL+#13+Application.ExeName),nil,nil,SW_SHOWNORMAL);
  Application.Terminate;
end;

This procedure is supposed to restart the application. I am certain that the deleting problem is caused by the quick start of the second application, because if I restart it myself, giving it a little time, the files get deleted normally.

tl;dr version: I need to call ShellExecute() which waits a bit (0.1 sec or so) and THEN executes the command.

Note

I tried using the -ping command to try to delay it, but it didn't work.

Thank you very much in advance

Edit: Rephrased

I need this to happen || First app closes; Wait 100 ms; second app opens ||. I need to call ShellExecute first, then wait until the calling application closes itself completely, then execute the shell (i.e. open second application)

解决方案

You're doing an autopatcher right ?

I've had the same problem and this is how I bypassed it :

You run second app with argument "--delay" or something like that. Second app handles argument "--delay" and sleeps for 100 ms, then continues running normally.

这篇关于ShellExecute执行前等待?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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