0
MS UIA 프레임 워크 및 기본 제공 자동화 이벤트 처리 작업을하고 있습니다. WindowClosedEvent에서 예기치 않은 동작이 나타납니다.자동화 이벤트 처리기가 두 번 이상 발생합니다.
아마 내가 여기서 잘못하고있는 것이지만, 콘솔 호출이 한 번 실행되어야한다는 것을 이해했습니다. 위 코드를 실행하면 콘솔 행이 두 번 실행됩니다.
내 TestApp이 닫힐 때 실행되는 특별한 이벤트가 없습니다. 테스트 응용 프로그램은 WPF 단일 창이기도합니다.
[TestMethod]
public void TestMethod1()
{
Process.Start(@"TestApp.exe");
Thread.Sleep(2000); //sleep to wait for proc to boot with ui
var windowElement = AutomationElement.RootElement.FindFirst(TreeScope.Descendants,
new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window),
new PropertyCondition(AutomationElement.NameProperty, "TestApp"), new PropertyCondition(AutomationElement.AutomationIdProperty, "TestAppAutomationId")));
Automation.AddAutomationEventHandler(WindowPattern.WindowClosedEvent, windowElement, TreeScope.Element,
OnClose);
var windowPattern = (WindowPattern)windowElement.GetCurrentPattern(WindowPattern.Pattern);
windowPattern.Close();
Thread.Sleep(2000); //sleep to wait for uia's event threads to fire and finish.
}
public void OnClose(object sender, AutomationEventArgs e)
{
Console.WriteLine("test"); //this is run twice during the test
}
내가 핸들러가 여러 번 알려 주시기 바랍니다보다 화재 원인이 여기에 뭔가를 잘못하고 있어요 경우 나 윈도우 10
에 .NET 4.5.2에 대해 실행하고 있습니다.
감사합니다.
@nouman을 제발하지 함수에 전달
위의 이벤트가 속성 값을 반환 전화를 발견하다 당신이 외치는 것처럼 보이는 대문자를 사용하십시오. –
나는이 퍼즐을 풀었습니다. –