/// <summary> /// Gets WCT information for the specified thread. /// </summary> public ThreadWCTInfo GetBlockingObjects(uint osThreadId) { IntPtr wctSession = IntPtr.Zero; try { wctSession = OpenThreadWaitChainSession((int)WCT_SESSION_OPEN_FLAGS.WCT_SYNC_OPEN_FLAG, 0); if (wctSession == IntPtr.Zero) return null; WAITCHAIN_NODE_INFO[] nodes = new WAITCHAIN_NODE_INFO[WCT_MAX_NODE_COUNT]; int isCycle = 0; int count = nodes.Length; if (GetThreadWaitChain(wctSession, IntPtr.Zero, WCTP_GETINFO_ALL_FLAGS, osThreadId, ref count, nodes, out isCycle)) { return new ThreadWCTInfo(isCycle == 1, osThreadId, nodes.Take(count).ToArray()); } } finally { if (wctSession != IntPtr.Zero) CloseThreadWaitChainSession(wctSession); } return null; }
/// <summary> /// Gets WCT information for the specified thread. /// </summary> public ThreadWCTInfo GetBlockingObjects(uint osThreadId) { IntPtr wctSession = IntPtr.Zero; try { wctSession = OpenThreadWaitChainSession((int)WCT_SESSION_OPEN_FLAGS.WCT_SYNC_OPEN_FLAG, 0); if (wctSession == IntPtr.Zero) { return(null); } WAITCHAIN_NODE_INFO[] nodes = new WAITCHAIN_NODE_INFO[WCT_MAX_NODE_COUNT]; int isCycle = 0; int count = nodes.Length; if (GetThreadWaitChain(wctSession, IntPtr.Zero, WCTP_GETINFO_ALL_FLAGS, osThreadId, ref count, nodes, out isCycle)) { return(new ThreadWCTInfo(isCycle == 1, osThreadId, nodes.Take(count).ToArray())); } } finally { if (wctSession != IntPtr.Zero) { CloseThreadWaitChainSession(wctSession); } } return(null); }
public void ThreadWaitChainSessionTest() { RegisterWaitChainCOMCallback(); using (new ElevPriv("SeDebugPrivilege")) using (var hWct = OpenThreadWaitChainSession(WaitChainSessionType.WCT_SYNC_OPEN_FLAG)) { Assert.That(hWct, ResultIs.ValidHandle); var nodes = new WAITCHAIN_NODE_INFO[WCT_MAX_NODE_COUNT]; uint nodeCnt = (uint)nodes.Length; Assert.That(GetThreadWaitChain(hWct, default, WaitChainRetrievalOptions.WCTP_GETINFO_ALL_FLAGS, Kernel32.GetCurrentThreadId(),
public WaitChainInfoObject(WAITCHAIN_NODE_INFO item) { ObjectStatus = item.ObjectStatus; ObjectType = item.ObjectType; TimeOut = item.Union.LockObject.Timeout; Alertable = item.Union.LockObject.Alertable; if (item.ObjectType == WCT_OBJECT_TYPE.WctThreadType) { OSThreadId = item.Union.ThreadObject.ThreadId; OSProcessId = item.Union.ThreadObject.ProcessId; ContextSwitches = item.Union.ThreadObject.ContextSwitches; WaitTime = item.Union.ThreadObject.WaitTime; } else { unsafe { ObjectName = Marshal.PtrToStringUni((IntPtr)item.Union.LockObject.ObjectName); } } }
public static bool GetThreadWaitChain(SafeWaitChainHandle chainHandle, int threadId, ref int NodeCount, WAITCHAIN_NODE_INFO[] NodeInfoArray, out int IsCycle) { return RealGetThreadWaitChain(chainHandle, IntPtr.Zero, WCT_FLAGS.All, threadId, ref NodeCount, NodeInfoArray, out IsCycle); }
public ThreadWCTInfo(bool isDeadLock, uint threadId, WAITCHAIN_NODE_INFO[] info) { IsDeadlocked = isDeadLock; OSThreadId = threadId; WaitChain.AddRange(info.Select(i => new WaitChainInfoObject(i))); }