How to use while(true) in my case? The idea is this: to display text from another program's textbox , into one's form. On click, everything works, but I would like to monitor this textbox with an interval of 1s ...
void Button2Click(object sender, EventArgs e) { var hWndParent = FindWindow(null, "Test(GetLbl)"); Thread thread = new Thread(() => FindChild(hWndParent)); thread.Start(); thread.IsBackground = true; } public void FindChild(IntPtr hWndParent){ while(true){ EnumChildWindows(hWndParent, new EnumWindowsProc(( hWnd, lParam ) => { if (GetParent(hWnd) != hWndParent){ return true; } FindChild(hWnd); if(GetText(hWnd).StartsWith("This is my Rich")){ if(label1.InvokeRequired){ label1.Invoke(new MethodInvoker(delegate { label1.Text = GetText(hWnd); })); } } return true; }), IntPtr.Zero); Thread.Sleep(1000); }