Repository navigation
Closed
Description
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!
Reacted by Dave
Metadata
Metadata
Assignees
Labels
No labels
Activity
yannduran commentedon Jun 12, 2021
@lsoft this isn't directed at you or what you wrote, I'm just talking generally.
Details like this should be totally hidden from the user of the API. All these cookies and weird names come from 20-odd years ago, if not more, using arcane COM naming standards and practices.
We should be aiming to hide all of that behind a more modern and simpler facade.
asynccode in a method that can't be madeasyncVS.StatusBar.StartStatusBarAnimationAsyncWhatever the implementation ends up being, it shouldn't drive what the API looks like.
All start bar operations would need something like:
var statusBar = VS.StatusBar.Initialise()/await VS.StatusBar.InitialiseAsync()usingstatementDispose()method could also be publicly exposedusingstatementlsoft commentedon Jun 12, 2021
@yannduran I completely agree. But, regardless of statusbar API design, I would like to know how to operate with cookies 100% correctly. It was my primary point to open this issue.
There are a lot of cookies in vsix development, you know that better than me :) StatusBar,
IVsOperationProgressStatusService, AdviseSolutionEvents... I think we need to know how to work with cookies correctly. After that, advanced statusbar API and its implementation can be discussed in details.Thanks for your thoughs!
yannduran commentedon Jun 13, 2021
@lsoft fair enough :-)
Perhaps it'd be better to add your question to discussions. Might I suggest 'How to properly handle cookies?' as a title?
Your title for this issue was a bit misleading if what you want to know is 'how to operate with cookies 100% correctly'.
[-]Doubts about status bar progress implementation[/-][+]Doubts about status bar progress implementation + how to operate with cookies 100% correctly[/+]