VisualStudio-ColorCoder
VisualStudio-ColorCoder copied to clipboard
ManageCache method, avoid Task.Wait
I believe it's the safer alternative to use Task.Wait:
public CacheState ManageCache(ref ProviderCache cache, NormalizedSnapshotSpanCollection spans, ITextBuffer buffer)
{
if (cache != null && cache.Snapshot == spans[0].Snapshot)
{
return CacheState.Resolved;
}
ProviderCache cache1 = null;
var result = ThreadHelper.JoinableTaskFactory.Run<CacheState>(async () =>
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
try
{
cache1 = await ProviderCache.ResolveAsync(buffer, spans[0].Snapshot);
return cache1 == null ? CacheState.NotResolved : CacheState.Resolved;
}
catch (Exception ex)
{
Log.LogError(ex.ToString());
return CacheState.NotResolved;
}
});
cache = cache1;
return result;
}