Skip to content

Doubts about status bar progress implementation + how to operate with cookies 100% correctlyΒ #60

@lsoft

Description

@lsoft

Do we really need to send cookie = 0 in each invocation of statusBar.Progress? If I understand status bar API correcty, I think we need to reuse same value of the cookie between our progress change invocation.

So we need to grab an our new cookie:

uint _cookie = 0; //zero matters!
_statusBar.Progress(ref _cookie, 1, "", 0, 0);

and then reuse it until our progress has finished. I really don't know what way is 100% correct, can anyone shed light on it?

if I right about reusing cookie value, I would suggest the following API:

//in VS.Notification we put:
        public async Task<StatusBarProgress> StartStatusBarAnimationAsync()
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
            IVsStatusbar? statusBar = await GetStatusBarAsync();

            return new StatusBarProgress(statusBar);
        }

        public class StatusBarProgress : IDisposable
        {
            private readonly IVsStatusbar _statusBar;
            private uint _cookie;

            public StatusBarProgress(IVsStatusbar statusBar)
            {
                ThreadHelper.ThrowIfNotOnUIThread();

                _statusBar = statusBar ?? throw new ArgumentNullException(nameof(statusBar));

                _statusBar.FreezeOutput(0);
                _statusBar.Progress(ref _cookie, 1, "", 0, 0); //grab our cookie
            }

            public void SetProgress(string text, int currentStep, int numberOfSteps)
            {
                ThreadHelper.ThrowIfNotOnUIThread();
                _statusBar.Progress(ref _cookie, 1, text, (uint)currentStep, (uint)numberOfSteps);
            }

            public void Dispose()
            {
                ThreadHelper.ThrowIfNotOnUIThread();
                _statusBar.Progress(ref _cookie, 0, "", 0, 0); //please make note that fInProgress = 0; it works because _cookie is not zero
            }
        }

//using it:
            using (var statusBarAnimation = await VS.Notifications.StartStatusBarAnimationAsync())
            {
                statusBarAnimation.SetProgress("1", 1, 3); //show first progress step
                await Task.Delay(1000);
                statusBarAnimation.SetProgress("0", 0, 3); //hide our progress for a second
                await Task.Delay(1000);
                statusBarAnimation.SetProgress("2", 2, 3); //reshow it
                await Task.Delay(1000);
            }

In this design we allowed to use currentStep = 0 to temporarily hide progress, because animation stops in the Dispose method. Also, both examples in the last episode demonstrates same behaviour with cookie.

any thoughs?
Thanks guys!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions