0

OS: win7 32bit

.net:3.5

以下の関数(スレッドで実行される)を使用して、ジョブイベントハンドルを実行しましたが、すべて問題ありません。

private void JobEventThread()
{
    uint jobEvent = 0;
    UIntPtr comKey;
    IntPtr Overlapped;
    bool bGoOn = true;
    while (bGoOn 
        && Kernel32Dll.GetQueuedCompletionStatus
                (m_hiocp, out jobEvent, out comKey, out Overlapped, Win32Define.INFINITE))
    {
        if (comKey.ToUInt32() == completeKey)
        {
            switch (jobEvent)
            {
                case Win32Define.JOB_OBJECT_MSG_NEW_PROCESS:
                    int pid = Overlapped.ToInt32();
                    if (NewProcessEvent != null){NewProcessEvent(pid, GetProcessNameById(pid));}
                    break;

                case Win32Define.JOB_OBJECT_MSG_EXIT_PROCESS:
                    if (ExitProcessEvent != null) { ExitProcessEvent(Overlapped.ToInt32()); }
                    break;

                case Win32Define.JOB_OBJECT_MSG_ACTIVE_PROCESS_ZERO:
                    if (ExitJobEvent != null) { ExitJobEvent(); }
                    bGoOn = false;
                    break;
            }
        }
    }
}

しかし、私は DispatchTimer でそのようなことをしようとしましたが、GetQueuedCompletionStatus は常に false を返します。

private void JobEventThread(object sender, EventArgs e)
{
    uint jobEvent = 0;
    UIntPtr comKey;
    IntPtr Overlapped;
    if (Kernel32Dll.GetQueuedCompletionStatus
                (m_hiocp, out jobEvent, out comKey, out Overlapped, 0))
    {
        if (comKey.ToUInt32() == completeKey)
        {
            switch (jobEvent)
            {
                case Win32Define.JOB_OBJECT_MSG_NEW_PROCESS:
                    int pid = Overlapped.ToInt32();
                    if (NewProcessEvent != null){NewProcessEvent(pid, GetProcessNameById(pid));}
                    break;

                case Win32Define.JOB_OBJECT_MSG_EXIT_PROCESS:
                    if (ExitProcessEvent != null) { ExitProcessEvent(Overlapped.ToInt32()); }
                    break;

                case Win32Define.JOB_OBJECT_MSG_ACTIVE_PROCESS_ZERO:
                    if (ExitJobEvent != null) { ExitJobEvent(); }
                    break;

                default:
                    break;
            }
        }
    }
}

イベントをスレッドから発生させたくないので、プログラムが複雑になります!

4

0 に答える 0