我用 c# 创建了一个工作
public WindowsJob()
{
m_handle = Kernel32Dll.CreateJobObject(IntPtr.Zero, null);
SetJobInformation();
SetJobCompletionPort();
}
private void SetJobInformation()
{
var info = new Win32Define.JOBOBJECT_BASIC_LIMIT_INFORMATION
{
LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE,
};
var extendedInfo = new Win32Define.JOBOBJECT_EXTENDED_LIMIT_INFORMATION
{
BasicLimitInformation = info
};
int length = Marshal.SizeOf(typeof(Win32Define.JOBOBJECT_EXTENDED_LIMIT_INFORMATION));
IntPtr extendedInfoPtr = Marshal.AllocHGlobal(length);
Marshal.StructureToPtr(extendedInfo, extendedInfoPtr, false);
if (!Kernel32Dll.SetInformationJobObject(m_handle
, Win32Define.JobObjectInfoType.JobObjectExtendedLimitInformation
, extendedInfoPtr, (uint)length))
throw new Exception(string.Format("Unable to set information. Error: {0}", Marshal.GetLastWin32Error()));
}
i can catch JOB_OBJECT_MSG_NEW_PROCESS, JOB_OBJECT_MSG_EXIT_PROCESS, JOB_OBJECT_MSG_ACTIVE_PROCESS_ZERO, but i can't catch JOB_OBJECT_MSG_ABNORMAL_EXIT_PROCESS (i write ac# program which throw new System.Exception("not handled") to kill itself, and it be caught by JOB_OBJECT_MSG_EXIT_PROCESS rather than JOB_OBJECT_MSG_ABNORMAL_EXIT_PROCESS).
我尝试了本地程序,它也不能被 JOB_OBJECT_MSG_ABNORMAL_EXIT_PROCESS 捕获。
为什么?我有什么错误吗?