Skip to content

Commit c3a5d52

Browse files
author
Maria Solano
committed
Use events listener cookie
1 parent 9c32305 commit c3a5d52

File tree

1 file changed

+3
-1
lines changed
  • src/toolkit/Community.VisualStudio.Toolkit.Shared/Notifications

1 file changed

+3
-1
lines changed

src/toolkit/Community.VisualStudio.Toolkit.Shared/Notifications/InfoBar.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.
@@ -119,7 +120,7 @@ public async Task<bool> TryShowInfoBarUIAsync()
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
{
@@ -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

Comments
 (0)