Skip to content

ManageCache method, avoid Task.Wait #18

Description

@lsoft

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;
        }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions