@@ -23,15 +23,26 @@ internal SelectionEvents()
2323 /// Fires when the selection changes
2424 /// </summary>
2525 public event EventHandler < SelectionChangedEventArgs > ? SelectionChanged ;
26-
26+
2727 /// <summary>
2828 /// Fires when the UI Context changes.
2929 /// </summary>
30- public event EventHandler < UIContextChangedEventArgs > ? UIContextChanged ;
30+ public event EventHandler < UIContextChangedEventArgs > ? UIContextChanged ;
3131
3232 int IVsSelectionEvents . OnSelectionChanged ( IVsHierarchy pHierOld , uint itemidOld , IVsMultiItemSelect pMISOld , ISelectionContainer pSCOld , IVsHierarchy pHierNew , uint itemidNew , IVsMultiItemSelect pMISNew , ISelectionContainer pSCNew )
3333 {
34- SelectionChanged ? . Invoke ( this , new SelectionChangedEventArgs ( pHierOld , pHierNew ) ) ;
34+ ThreadHelper . ThrowIfNotOnUIThread ( ) ;
35+
36+ ThreadHelper . JoinableTaskFactory . RunAsync ( async delegate
37+ {
38+ await ThreadHelper . JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
39+
40+ IVsHierarchyItem ? from = await pHierOld . ToHierarcyItemAsync ( itemidOld ) ;
41+ IVsHierarchyItem ? to = await pHierNew . ToHierarcyItemAsync ( itemidNew ) ;
42+
43+ SelectionChanged ? . Invoke ( this , new SelectionChangedEventArgs ( from , to ) ) ;
44+ } ) . FireAndForget ( ) ;
45+
3546 return VSConstants . S_OK ;
3647 }
3748
@@ -55,7 +66,7 @@ public class SelectionChangedEventArgs : EventArgs
5566 /// <summary>
5667 /// Creates a new instance of the EventArgs.
5768 /// </summary>
58- public SelectionChangedEventArgs ( IVsHierarchy from , IVsHierarchy to )
69+ public SelectionChangedEventArgs ( IVsHierarchyItem ? from , IVsHierarchyItem ? to )
5970 {
6071 From = from ;
6172 To = to ;
@@ -64,11 +75,11 @@ public SelectionChangedEventArgs(IVsHierarchy from, IVsHierarchy to)
6475 /// <summary>
6576 /// What the selection was before the change.
6677 /// </summary>
67- public IVsHierarchy From { get ; }
78+ public IVsHierarchyItem ? From { get ; }
6879
6980 /// <summary>
7081 /// What the selection is currently after the change.
7182 /// </summary>
72- public IVsHierarchy To { get ; }
83+ public IVsHierarchyItem ? To { get ; }
7384 }
7485}
0 commit comments