Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ManageCache method, avoid Task.Wait #18

Open
lsoft opened this issue Mar 6, 2022 · 0 comments
Open

ManageCache method, avoid Task.Wait #18

lsoft opened this issue Mar 6, 2022 · 0 comments

Comments

@lsoft
Copy link

lsoft commented Mar 6, 2022

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;
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant