Skip to content

Commit a1f6fa1

Browse files
committed
CoverageColorProvider replace ThrowIfNotOnUIThread with SwitchToMainThreadAsync.
1 parent f76db52 commit a1f6fa1

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

SharedProject/Impl/CoverageColorProvider.cs

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -102,29 +102,33 @@ private void UpdateFromFontsAndColorsIfNecessary()
102102

103103
private void UpdateColoursFromFontsAndColors()
104104
{
105-
ThreadHelper.ThrowIfNotOnUIThread();
106-
var success = fontAndColorStorage.OpenCategory(ref categoryWithCoverage, storeFlags);
107-
if (success == VSConstants.S_OK)
105+
ThreadHelper.JoinableTaskFactory.Run(async () =>
108106
{
109-
CoverageTouchedArea = GetColor("Coverage Touched Area");
110-
CoverageNotTouchedArea = GetColor("Coverage Not Touched Area");
111-
CoveragePartiallyTouchedArea = GetColor("Coverage Partially Touched Area");
112-
}
113-
fontAndColorStorage.CloseCategory();
114-
//throw ?
115-
requiresFromFontsAndColours = false;
116-
}
117-
118-
private System.Windows.Media.Color GetColor(string displayName)
119-
{
120-
ThreadHelper.ThrowIfNotOnUIThread();
121-
var touchAreaInfo = new ColorableItemInfo[1];
122-
var getItemSuccess = fontAndColorStorage.GetItem(displayName, touchAreaInfo);
123-
if (getItemSuccess == VSConstants.S_OK)
124-
{
125-
return ParseColor(touchAreaInfo[0].crBackground);
126-
}
127-
throw new Exception("Failed to get color");
107+
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
108+
var success = fontAndColorStorage.OpenCategory(ref categoryWithCoverage, storeFlags);
109+
if (success == VSConstants.S_OK)
110+
{
111+
// https://github.com/microsoft/vs-threading/issues/993
112+
System.Windows.Media.Color GetColor(string displayName)
113+
{
114+
var touchAreaInfo = new ColorableItemInfo[1];
115+
var getItemSuccess = fontAndColorStorage.GetItem(displayName, touchAreaInfo);
116+
if (getItemSuccess == VSConstants.S_OK)
117+
{
118+
return ParseColor(touchAreaInfo[0].crBackground);
119+
}
120+
throw new Exception("Failed to get color");
121+
}
122+
123+
CoverageTouchedArea = GetColor("Coverage Touched Area");
124+
CoverageNotTouchedArea = GetColor("Coverage Not Touched Area");
125+
CoveragePartiallyTouchedArea = GetColor("Coverage Partially Touched Area");
126+
}
127+
fontAndColorStorage.CloseCategory();
128+
//throw ?
129+
requiresFromFontsAndColours = false;
130+
});
131+
128132
}
129133

130134
private System.Windows.Media.Color ParseColor(uint color)
@@ -133,7 +137,6 @@ private System.Windows.Media.Color ParseColor(uint color)
133137
return System.Windows.Media.Color.FromArgb(dcolor.A, dcolor.R, dcolor.G, dcolor.B);
134138
}
135139

136-
137140
}
138141

139142
}

0 commit comments

Comments
 (0)