in src/Desktop/UIAutomation/EventHandlers/EventListenerFactory.cs [224:335]
private void UnregisterEventListener(EventListenerFactoryMessage msgData)
{
HandleUIAutomationEventMessage listener = null;
try
{
switch (msgData.EventId)
{
case EventType.UIA_AutomationFocusChangedEventId:
if (this.EventListenerFocusChanged != null)
{
listener = this.EventListenerFocusChanged.ListenEventMessage;
this.EventListenerFocusChanged.Dispose();
this.EventListenerFocusChanged = null;
}
break;
case EventType.UIA_StructureChangedEventId:
if (this.EventListenerStructureChanged != null)
{
listener = this.EventListenerStructureChanged.ListenEventMessage;
this.EventListenerStructureChanged.Dispose();
this.EventListenerStructureChanged = null;
}
break;
case EventType.UIA_AutomationPropertyChangedEventId:
if (this.EventListenerPropertyChanged != null)
{
listener = this.EventListenerPropertyChanged.ListenEventMessage;
this.EventListenerPropertyChanged.Dispose();
this.EventListenerPropertyChanged = null;
}
break;
case EventType.UIA_TextEdit_TextChangedEventId:
if (this.EventListenerTextEditTextChanged != null)
{
listener = this.EventListenerTextEditTextChanged.ListenEventMessage;
this.EventListenerTextEditTextChanged.Dispose();
this.EventListenerTextEditTextChanged = null;
}
break;
case EventType.UIA_ChangesEventId:
if (this.EventListenerChanges != null)
{
listener = this.EventListenerChanges.ListenEventMessage;
this.EventListenerChanges.Dispose();
this.EventListenerChanges = null;
}
break;
case EventType.UIA_NotificationEventId:
if (this.EventListenerNotification != null)
{
listener = this.EventListenerNotification.ListenEventMessage;
this.EventListenerNotification.Dispose();
this.EventListenerNotification = null;
}
break;
case EventType.UIA_ActiveTextPositionChangedEventId:
if (this.EventListenerActiveTextPositionChanged != null)
{
listener = this.EventListenerActiveTextPositionChanged.ListenEventMessage;
this.EventListenerActiveTextPositionChanged.Dispose();
this.EventListenerActiveTextPositionChanged = null;
}
break;
default:
if (this.EventListeners.ContainsKey(msgData.EventId))
{
var l = this.EventListeners[msgData.EventId];
listener = l.ListenEventMessage;
this.EventListeners.Remove(msgData.EventId);
l.Dispose();
}
break;
}
if (listener != null)
{
#pragma warning disable CA2000 // Call IDisposable.Dispose()
var m = EventMessage.GetInstance(EventType.UIA_EventRecorderNotificationEventId, null);
#pragma warning restore CA2000
m.Properties = new List<KeyValuePair<string, dynamic>>()
{
new KeyValuePair<string, dynamic>("Message", "Succeeded to unregister a event listeners"),
new KeyValuePair<string, dynamic>("Event Id", msgData.EventId),
new KeyValuePair<string, dynamic>("Event Name", EventType.GetInstance().GetNameById(msgData.EventId)),
};
listener(m);
}
}
#pragma warning disable CA1031 // Do not catch general exception types
catch (Exception e)
{
e.ReportException();
#pragma warning disable CA2000 // Call IDisposable.Dispose()
var m = EventMessage.GetInstance(EventType.UIA_EventRecorderNotificationEventId, null);
#pragma warning restore CA2000
m.Properties = new List<KeyValuePair<string, dynamic>>()
{
new KeyValuePair<string, dynamic>("Message", "Failed to unregister a event listeners"),
new KeyValuePair<string, dynamic>("Event Id", msgData.EventId),
new KeyValuePair<string, dynamic>("Event Name", EventType.GetInstance().GetNameById(msgData.EventId)),
new KeyValuePair<string, dynamic>("Error", e.Message)
};
listener(m);
/// it is very unexpected situation.
/// need to figure out a way to prevent it or handle it more gracefully
}
#pragma warning restore CA1031 // Do not catch general exception types
}