private static void RecorderThread() { StringBuilder sb = new StringBuilder(NativeMethods.BUFFERSIZE); System.Drawing.Point pt = new System.Drawing.Point(0, 0); while (true) { bool bStartWalk = s_eventRecordNow.WaitOne(nDelayRecord); PublishKeyboardInput(); if (s_eventQuitRecording.WaitOne(0)) { break; } NativeMethods.GetPhysicalCursorPos(out pt); int dist = Math.Abs(pt.X - ptUiWalking.X) + Math.Abs(pt.Y - ptUiWalking.Y); if (bStartWalk && MouseKeyboardHook.s_bPauseMouseKeyboard == false) { // check if cursor has moved if (dist > nMinDist) { NativeMethods.PostMessage(MainWindow.s_windowHandle, (int)MainWindow.UiThreadTask.Active, 0, 0); ptUiWalking.X = pt.X; ptUiWalking.Y = pt.Y; var tick = Environment.TickCount; NativeMethods.GetUiXPath(ptUiWalking.X, ptUiWalking.Y, sb, sb.Capacity); AppInsights.LogMetric("GetUiXPathPerf", Environment.TickCount - tick); if (MouseKeyboardHook.s_bPauseMouseKeyboard == true) { continue; } if (s_eventQuitRecording.WaitOne(0)) { break; } string strXmlNode = sb.ToString(); if (!string.IsNullOrEmpty(strXmlNode)) { int nHash = strXmlNode.GetHashCode(); if (nHash != s_nPathHash) { lock (s_lockUiPath) { MouseKeyboardEventHandler.s_strXmlNodes = strXmlNode; s_nPathHash = nHash; } XmlNodePathRecorder.HandleUiEvent(ref s_strXmlNodes, EnumUiTaskName.Inspect, 0, 0); } } } s_eventRecordNow.Reset(); } } }