完成任何过程后获取句柄或消息. [英] Get Handle or message when any process completed.

查看:91
本文介绍了完成任何过程后获取句柄或消息.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Edited:
1) There are n number of process i.e. disk cleanup, disk fragmentation etc in my project.
2) User have check box facility to check which process he wants to execute and click on start button.
3) <b>Using WinExec i execute the first process with argument. but how to achieve that when this process complete than can i get the message or handle so that i run the other process</b>
4) If possible than can i get the time of process to complete the task.(It is second priority task for me)
<Edited>




如果我启动某些工具或过程,是否有可能获得该过程完成其任务的时间?
或者,当该过程完成时,我可以获取该句柄.

我在项目中想要的是这个;假设我的应用程序有n个进程,并且用户检查的任何进程都一个接一个地执行.

当一个过程完成后,下一个应该开始,如果可能的话,我将显示过程完成后的剩余时间.

示例:要分析磁盘,应用程序启动"chkdsk"实用程序来修复所有磁盘错误.
完成后,将执行其他进程.




在此先感谢..




If I launch some tool or process, can it be possible that I get the time when the process completes its task?
Or, that when the process is complete, that can I get the handle.

What I want in my project is this; Suppose my application has n number of processes and whatever process user checks, executes one by one.

When one process is complete then the next should start or if possible I will show the remaining time when process completed.

Example :To Analyze Disk,application launches "chkdsk" utility to fix any disk errors.
When it completes than other process is executed.




Thanks in advance..

推荐答案

在流程开始和结束时调用此方法
http://www.cplusplus.com/reference/clibrary/ctime/time/ [ ^ ]
(页面左侧列表中有几种可供选择)

(也请参见上面的评论)
Call this when the process starts and when it ends
http://www.cplusplus.com/reference/clibrary/ctime/time/[^]
(there are several to choose from in in the list on the left of the page)

(see my comment above as well)


您不能(因为在物理上是不可能的)知道在流程本身完成之前该流程所花费的时间.
这就像问博尔特先生要花多长时间才能运行100公吨.我们可以根据以前的运行进行估算,但是特定运行将持续多长时间,我们仅知道运行何时结束.

给出等待时间"的程序将基于该循环的先前迭代的持续时间来估计该循环的无持续时间.

不幸的是,磁盘扫描程序,碎片整理等并不仅具有线性循环,而且可能具有更多不一定具有相同长度的内部循环(因此,估算永远不会是精确的...)
如果您想知道一次扫描将花费多长时间,则只需估算该系统上一次运行所花费的时间(这将是非常不准确的),或者运行它并查看它可以为您提供什么估算. >
其他事情是……超心理学,而不是编程.
You cannot (because it is physically impossible) know the time spent by a process before the process itself complete.
It''s like asking Mr. Bolt how long will he take to run 100mt. We can estimate based on previous runs, but how long a specific run will be, we know only when the run will be over.

Programs that gives the "time to wait" are providing an estimation on a complessive duration of a loop based on the duration of that loop''s previous iteration.

Unfortunately, scandisk, defrag etc. don''t have just a linear loop, but may have more inner loops not necessarily of the same length (so an estimation will never be precise ...)
If you want to know how long a scan will take, you only have to estimate with the time taken by a previous run on that system (will be very inaccurate), or run it and see what estimation it can give you.

Other thing are ... parapsychology, not programming.


首先,使用 ^ ].
该函数的最后一个参数输出一个PROCESS_INFORMATION结构,该结构具有一个hProcess成员.
然后使用 WaitForSingleObject [ GetExitCodeProcess [ WaitForSingleObject [之后) ^ ]成功返回.您可以启动计时器并在任务完成时停止计时器( timeGetTime [ ^ ]对此非常有用),否则您可以使用函数 GetSystemTimeAsFileTime [
Firstly, Create the process using CreateProcess[^].
The last parameter of this function outputs a PROCESS_INFORMATION struct, which has a hProcess member.
Then use WaitForSingleObject[^] to wait for the PROCESS_INFORMATION.hProcess with a timeout of INFINITE (because defrag often takes ages).
Once completed, you can use GetExitCodeProcess[^] with the PROCESS_INFORMATION.hProcess if you care about the exit code (general convention is error will return a number with the highest bit set (i.e if (nRetCode & 0x80000000) { /*error*/ })

There are 2 ways of getting the execution time (after WaitForSingleObject[^] returned successfully. You can start a timer and stop it when the task completes (timeGetTime[^] would be pretty good for this), otherwise you can use the function GetProcessTimes[^] The 2nd parameter to this returns the time that the process was created, accurate to about 1ms, just get the current system time with GetSystemTimeAsFileTime[^] to get the difference in times (you may need to do this by converting them to an unsigned long long since they are a struct of 2 DWORDs)


这篇关于完成任何过程后获取句柄或消息.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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