Get name of window which is being closed using automation events c#
问题 I'm working on a project where I need to get the name of windows which is being closed . I'm using C# Automation events for this. I've pasted below the code that I'm using: Automation.AddAutomationEventHandler(WindowPattern.WindowClosedEvent, AutomationElement.RootElement, TreeScope.Subtree, (sender, eve) => { AutomationElement winElemnt = sender as AutomationElement; if (winElemnt != null) { Console.WriteLine("Window closed : " + winElemnt.Current.Name); } }); The above code get triggered