@@ -94,6 +94,7 @@ public class InfoBar : IVsInfoBarUIEvents
9494 private readonly IVsInfoBarHost _host ;
9595 private readonly InfoBarModel _model ;
9696 private IVsInfoBarUIElement ? _uiElement ;
97+ private uint _listenerCookie ;
9798
9899 /// <summary>
99100 /// Creates a new instance of the InfoBar in a specific window frame or document window.
@@ -112,14 +113,14 @@ internal InfoBar(IVsInfoBarHost host, InfoBarModel model)
112113 /// <summary>
113114 /// Displays the InfoBar in the tool window or document previously specified.
114115 /// </summary>
115- /// <returns><c> true</c > if the InfoBar was shown; otherwise <c> false</c >.</returns>
116+ /// <returns><see langword=" true" / > if the InfoBar was shown; otherwise <see langword=" false" / >.</returns>
116117 public async Task < bool > TryShowInfoBarUIAsync ( )
117118 {
118119 await ThreadHelper . JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
119120 IVsInfoBarUIFactory infoBarUIFactory = ( IVsInfoBarUIFactory ) await VS . GetRequiredServiceAsync < SVsInfoBarUIFactory , object > ( ) ;
120121
121122 _uiElement = infoBarUIFactory . CreateInfoBar ( _model ) ;
122- _uiElement . Advise ( this , out _ ) ;
123+ _uiElement . Advise ( this , out _listenerCookie ) ;
123124
124125 if ( _host != null )
125126 {
@@ -131,7 +132,7 @@ public async Task<bool> TryShowInfoBarUIAsync()
131132 }
132133
133134 /// <summary>
134- /// Attempts to get the underlying WPF UI element of the InfoBar
135+ /// Attempts to get the underlying WPF UI element of the InfoBar.
135136 /// </summary>
136137 public bool TryGetWpfElement ( out Control ? control )
137138 {
@@ -171,6 +172,7 @@ public void Close()
171172 void IVsInfoBarUIEvents . OnClosed ( IVsInfoBarUIElement infoBarUIElement )
172173 {
173174 IsVisible = false ;
175+ _uiElement ? . Unadvise ( _listenerCookie ) ;
174176 }
175177
176178 void IVsInfoBarUIEvents . OnActionItemClicked ( IVsInfoBarUIElement infoBarUIElement , IVsInfoBarActionItem actionItem )
0 commit comments