0

my code is below

IntPtr hwnd = FindWindow(null, "dingding");
GetWindowThreadProcessId(hwnd, out dingID);
var myapp = FlaUI.Core.Application.Attach(dingID);
var myautomation = new UIA3Automation());
var searchTextBox = dingdingWindow.FindFirstDescendant(cf => cf.ByName("search"))?.AsTextBox();

most time it works well but sometimes when it goes to "var serchTextBox........", the result is null and the hwnd is ok and dingID is ok and searchTextBox is spotted with inspect.exe. I have to relaunch my app, then everything goes fine.

I am just curious about that? Can somebody tell me why and how to modify the code?

zforgo
  • 2,508
  • 2
  • 14
  • 22
  • It might be a timing issue. The control you are looking for might not be initialized yet, even though its parent window already exists. I usually implement a retry loop to try to find the control periodically, with a short delay after each unsuccessful try. If after a given amount of time the control still can't be found, I throw a timeout exception. – zett42 May 31 '23 at 19:39
  • i've try a lot to find out which part is null , dingdingwindows or elements . the conclusion is dingdingwindow is ok when i use" if dingdingwindows is null throw SystemException" . but when i use "var allObj = dingdingWindow.FindAllChildren();" , the result is null . strange! – davidcat Jun 01 '23 at 08:20

0 Answers0