WCT GetThreadWaitChain调用始终返回false [英] WCT GetThreadWaitChain call allways return false

查看:282
本文介绍了WCT GetThreadWaitChain调用始终返回false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获取有关某个线程的WCT信息,但是每次我调用GetThreadWaitChain函数时,作为响应都会得到false,并且ref参数保持为零.

I am trying to get WCT information about some thread, but every time I am calling GetThreadWaitChain function I am getting false as a response and the ref parameters remain zero.

我做错了什么?

我正在调用WaitForMultipleObjects的线程上调用此函数,并且确保在调试时该线程等待.

I am calling this function on a thread which calls WaitForMultipleObjects, and I am making sure that this thread waits while I am debugging.

那是我的代码:

    internal void CollectWaitInformation(ClrThread thread)
    {
        var g_WctHandle = OpenThreadWaitChainSession(0, 0);

        uint threadID = thread.OSThreadId;

        WAITCHAIN_NODE_INFO[] NodeInfoArray = new WAITCHAIN_NODE_INFO[WCT_MAX_NODE_COUNT];


        int isCycle = 0;
        int count = 0;

        // Make a synchronous WCT call to retrieve the wait chain.
        bool result = GetThreadWaitChain(g_WctHandle,
                                IntPtr.Zero,
                                WCTP_GETINFO_ALL_FLAGS,
                                threadID, ref count, NodeInfoArray, out isCycle);

        if (!result)
        {
            //error
        }

        //Finaly ...
        CloseSession(g_WctHandle);
    }

    [DllImport("Advapi32.dll")]
    public static extern IntPtr OpenThreadWaitChainSession(OpenThreadChainFlags Flags, DWORD callback);

    [DllImport("Advapi32.dll")]
    public static extern bool GetThreadWaitChain(
        IntPtr WctHandle,
        IntPtr Context,
        UInt32 Flags,
        uint ThreadId,
        ref int NodeCount,
        [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 4)]
        [In, Out]
        WAITCHAIN_NODE_INFO[] NodeInfoArray,
        out int IsCycle
    );

    [StructLayout(LayoutKind.Sequential)]
    public struct WAITCHAIN_NODE_INFO
    {
        public WCT_OBJECT_TYPE ObjectType;
        public WCT_OBJECT_STATUS ObjectStatus;

        public struct LockObject
        {
            string ObjectName;
            LARGE_INTEGER Timeout;
            BOOL Alertable;
        }
        public struct ThreadObject
        {
            DWORD ProcessId;
            DWORD ThreadId;
            DWORD WaitTime;
            DWORD ContextSwitches;
        }
    }
}

}

在上一个问题的帮助下:

With a help from my previous question:

使用指针参数从C#调用C ++方法( WCT)

推荐答案

来自文档:

NodeCount [in,out]

输入时,从1到WCT_MAX_NODE_COUNT的数字指定等待链中的节点数.返回时,检索到的节点数.

On input, a number from 1 to WCT_MAX_NODE_COUNT that specifies the number of nodes in the wait chain. On return, the number of nodes retrieved.

....

您输入0不能满足此要求.

You fail to meet this requirement because you pass in 0.

这篇关于WCT GetThreadWaitChain调用始终返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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