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

(Created page with "通过指定的进程ID在ADE实例当中设置一个监控线程用来探测进程的结束,如果指定进程ID先结束,那么将终止ADE进程。在ADE运行的计算...")
 
(14 intermediate revisions by the same user not shown)
Line 9: Line 9:
 
通过指定的进程ID在ADE实例当中设置一个监控线程用来探测进程的结束,如果指定进程ID先结束,那么将终止ADE进程。在ADE运行的计算机上该进程必须退出。
 
通过指定的进程ID在ADE实例当中设置一个监控线程用来探测进程的结束,如果指定进程ID先结束,那么将终止ADE进程。在ADE运行的计算机上该进程必须退出。
  
Use of this function can help to guarantee that ADE processes are terminated even when your own calling code terminates abnormally, such as when you stop the code prematurely while debugging, or when your program crashes.  
+
通过使用该函数,可以帮助保证ADE进程在你的代码异常终止时也能正常结束,例如在调试过程中你过早地停止代码运行,或者在你的程序奔溃时。  
  
The COM protocol requires a caller to release each object that it uses, and out-of-process COM servers normally stay active until the last object is released.  In ADE's case, ADE will stay normally active until the calling process calls IUnknown::Release() on the object (a standard COM interface method).  A problem arises, however, when the calling process terminates prematurely, such as when it is killed during debugging or crashes. When that happens, the calling process never gets the chance to release the object, so ADE never gets the release signal, and thus continues to run.  (The same is true of any out-of-process COM server).
+
COM协议需要一个调用程序来释放其使用的每一个对象,进程外COM服务器一般情况下保持处于活动状态,直至最后的对象被释放。在ADE中,ADE将一般情况下保持处于活动状态,直至进程在该对象上调用IUnknown::Release()(标准的COM接口方法)。但是这时会出现一个问题,当调用的进程提前终止时,例如在调试过程中或者奔溃时被终止。当发生这种情况时,调用进程没有机会释放对象,因此ADE没有收到释放信号,将继续运行。(任何进程外COM服务器都是如此)。
  
By calling this method immediately after you start an out-of-process instance of ADE, supplying it with your own program's process ID, it enables ADE to monitor the status of your process, and detect when it is terminated.  Normally, your process will release the last [[CAEngine]] instance so that ADE will terminate first.  But should that not happen, the ADE.exe process will automatically terminate itself at the moment it detects your process has terminated.
+
在你开始一个进程外ADE实例后,立即通过调用该方法,为它提供你自己的程序进程ID,使ADE能够监视你的进程状态,并在它终止时探测。正常情况下,你的进程将释放最后的[[CAEngine/zh | CAEngine]]实例以便ADE将先结束。但是这不会发生,ADE.exe进程将在它探测到你的进程终止时自动终止其本身。
  
 
== 用法 ==
 
== 用法 ==
  
In VB.NET syntax, you would call this immediately following your acquisition of a [[CAEngine]], as follows:
+
在VB.NET语法中,你应该在获得[[CAEngine/zh | CAEngine]]后立刻条用,如下所示:
  
 
  Dim ade As [[CAEngine/zh | CAEngine]] = new CAEngine
 
  Dim ade As [[CAEngine/zh | CAEngine]] = new CAEngine
Line 25: Line 25:
 
= 返回值 =
 
= 返回值 =
  
Returns true if successful in setting up the monitor, false otherwise.
+
如果成功设置监控线程将返回ture,否则返回false。
  
The [[ErrorCode]], [[ErrorText]], and [[CAEngine::OutputBuffer|OutputBuffer]] properties provide more information on the nature of the error when unsuccessful. Possible error codes include:
+
[[CAEngine::ErrorCode/zh | ErrorCode]][[CAEngine::ErrorText/zh | ErrorText]],和[[CAEngine::OutputBuffer/zh | OutputBuffer]] 属性提供关于未成功时错误本质的更多信息。可能的错误代码包括:
  
* 85 - [[CAEngine::MonitorProcess]](pid) could not open the indicated process id
+
* 85 - [[CAEngine::MonitorProcess/zh | CAEngine::MonitorProcess]](pid) 无法打开指定的进程ID。
  
 
= 注意 =
 
= 注意 =
  
You cannot ''unmonitor'' a process.  Once a monitor is established, it will continue until ADE terminates.
+
你不能对一个进程''取消监控''。一旦监控线程被建立,它将一直存在直到ADE终止。
  
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.
+
你可以使用不同的pid(进程名称)多次调用。当这样做时,ADE将监视所有指定进程,任何一个进程结束它都将结束。
  
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.
+
你只能在ADE.exe运行的计算机上监视进程。如果你通过DCOM使用远程ADE.exe,这将不能工作。
  
The process monitored does not have to be the calling process.  All you need is the pid for it.
+
被监视的进程没有必要调用是调用的进程。你所需要的是它的pid。
  
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 [http://msdn.microsoft.com/en-us/library/ms684320(VS.85).aspx OpenProcess]] for more detail).  It would be unusual to not have this permission, but not impossible.
+
你的安全设置必须是:ADE.exe进程账户允许它通过同步许可获取指定进程句柄(详细信息请参考[[http://msdn.microsoft.com/en-us/library/ms684320(VS.85).aspx OpenProcess]])。没有该许可是不同寻常的,但并非不可能。
  
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:
+
该方法在ADE 4.2 COM API中没有曝光,因此你必须等待ADE4.3的"正式"发布。然而,在4.2.3程序补丁里有一个后门,这样能够通过自动化API接口调用。因此,从4.2.3开始你可以这样做:
  
 
   Dim adeObj As Object = ade
 
   Dim adeObj As Object = ade
 
   ade.MonitorProcess(System.Diagnostics.Process.GetCurrentProcess().Id)
 
   ade.MonitorProcess(System.Diagnostics.Process.GetCurrentProcess().Id)

Latest revision as of 02:16, 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。

 ErrorCode ErrorText,和 OutputBuffer 属性提供关于未成功时错误本质的更多信息。可能的错误代码包括:

注意

你不能对一个进程取消监控。一旦监控线程被建立,它将一直存在直到ADE终止。

你可以使用不同的pid(进程名称)多次调用。当这样做时,ADE将监视所有指定进程,任何一个进程结束它都将结束。

你只能在ADE.exe运行的计算机上监视进程。如果你通过DCOM使用远程ADE.exe,这将不能工作。

被监视的进程没有必要调用是调用的进程。你所需要的是它的pid。

你的安全设置必须是:ADE.exe进程账户允许它通过同步许可获取指定进程句柄(详细信息请参考[OpenProcess])。没有该许可是不同寻常的,但并非不可能。

该方法在ADE 4.2 COM API中没有曝光,因此你必须等待ADE4.3的"正式"发布。然而,在4.2.3程序补丁里有一个后门,这样能够通过自动化API接口调用。因此,从4.2.3开始你可以这样做:

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


You are not allowed to post comments.