Difference between revisions of "CAEngine::MonitorProcess/zh"

(Created page with "如果成功设置监控线程将返回ture,否则返回false。")
(Created page with "* 85 - CAEngine::MonitorProcess(pid) 无法打开指定的进程ID。")
Line 29: Line 29:
 
The [[ErrorCode]], [[ErrorText]], and [[CAEngine::OutputBuffer|OutputBuffer]] properties provide more information on the nature of the error when unsuccessful. Possible error codes include:
 
The [[ErrorCode]], [[ErrorText]], and [[CAEngine::OutputBuffer|OutputBuffer]] properties provide more information on the nature of the error when unsuccessful. Possible error codes include:
  
* 85 - [[CAEngine::MonitorProcess]](pid) could not open the indicated process id
+
* 85 - [[CAEngine::MonitorProcess/zh | CAEngine::MonitorProcess]](pid) 无法打开指定的进程ID。
  
 
= 注意 =
 
= 注意 =

Revision as of 01:26, 21 October 2015

ADE User Guide > ADE Server Class Reference > CAEngine

Other languages:
English • ‎中文

(ADE 4.3新特征)

CAEngine::MonitorProcess(long pid)

通过指定的进程ID在ADE实例当中设置一个监控线程用来探测进程的结束,如果指定进程ID先结束,那么将终止ADE进程。在ADE运行的计算机上该进程必须退出。

通过使用该函数,可以帮助保证ADE进程在你的代码异常终止时也能正常结束,例如在调试过程中你过早地停止代码运行,或者在你的程序奔溃时。

COM协议需要一个调用程序来释放其使用的每一个对象,进程外COM服务器一般情况下保持处于活动状态,直至最后的对象被释放。在ADE中,ADE将一般情况下保持处于活动状态,直至进程在该对象上调用IUnknown::Release()(标准的COM接口方法)。但是这时会出现一个问题,当调用的进程提前终止时,例如在调试过程中或者奔溃时被终止。当发生这种情况时,调用进程没有机会释放对象,因此ADE没有收到释放信号,将继续运行。(任何进程外COM服务器都是如此)。

在你开始一个进程外ADE实例后,立即通过调用该方法,为它提供你自己的程序进程ID,使ADE能够监视你的进程状态,并在它终止时探测。正常情况下,你的进程将释放最后的 CAEngine实例以便ADE将先结束。但是这不会发生,ADE.exe进程将在它探测到你的进程终止时自动终止其本身。

用法

在VB.NET语法中,你应该在获得 CAEngine后立刻条用,如下所示:

Dim ade As  CAEngine = new CAEngine
Dim pid As Long = System.Diagnostics.Process.GetCurrentProcess().Id
ade.MonitorProcess(pid)

返回值

如果成功设置监控线程将返回ture,否则返回false。

The ErrorCode, ErrorText, and OutputBuffer properties provide more information on the nature of the error when unsuccessful. Possible error codes include:

注意

You cannot unmonitor a process. Once a monitor is established, it will continue until ADE terminates.

You can call this multiple times with different pid. When doing so, ADE will watch all indicated processes, and terminate itself if any of them terminate.

You can only monitor processes on the same machine that ADE.exe is running on. If you are using a remote ADE.exe through DCOM, this doesn't work.

The process monitored does not have to be the calling process. All you need is the pid for it.

Your security settings must be such that the ADE.exe process's account allows it permission to obtain a handle to the indicated process with SYNCHRONIZE permission (see OpenProcess] for more detail). It would be unusual to not have this permission, but not impossible.

The method is not exposed in the the ADE 4.2 COM API, so "officially" you'll have to wait for the release of ADE 4.3. However, there is a back door in patch release 4.2.3, in that it can be called through the Automation API. Thus, from 4.2.3+ you could do this:

 Dim adeObj As Object = ade
 ade.MonitorProcess(System.Diagnostics.Process.GetCurrentProcess().Id)
Comments


You are not allowed to post comments.