@@ -10,8 +10,8 @@ namespace BenchmarkDotNetVisualizer.Utilities;
1010public static partial class HtmlHelper
1111{
1212 private static readonly BrowserFetcher _browserFetcher = new ( ) ;
13- private static readonly SemaphoreSlim _browserDownloadSync = new ( 1 , 1 ) ;
14- private static readonly SemaphoreSlim _consoleProgressSync = new ( 1 , 1 ) ;
13+ private static readonly SemaphoreSlim _browserDownloadLock = new ( 1 , 1 ) ;
14+ private static readonly SemaphoreSlim _consolePrintLock = new ( 1 , 1 ) ;
1515
1616 /// <summary>
1717 /// Gets or sets the default browser
@@ -104,7 +104,7 @@ public static async Task EnsureBrowserDownloadedAsync(bool silent = false)
104104 {
105105 try
106106 {
107- await _browserDownloadSync . WaitAsync ( ) ;
107+ await _browserDownloadLock . WaitAsync ( ) ;
108108
109109 if ( DefaultBrowser is not null )
110110 return ;
@@ -115,24 +115,26 @@ public static async Task EnsureBrowserDownloadedAsync(bool silent = false)
115115 }
116116 finally
117117 {
118- _browserDownloadSync . Release ( ) ;
118+ _browserDownloadLock . Release ( ) ;
119119 }
120120 } )
121121 } ;
122122
123- var isProgressing = await _consoleProgressSync . IsLockAlreadyAcquiredAsync ( ) ;
124- if ( silent is false && isProgressing is false )
123+ await Task . Delay ( 1000 ) ;
124+
125+ if ( silent is false //print progress to console
126+ && await _consolePrintLock . IsLockAlreadyAcquiredAsync ( ) is false //is not already printing to console
127+ && await _browserDownloadLock . IsLockAlreadyAcquiredAsync ( ) //browser is downloading
128+ )
125129 {
126130 tasks . Add ( Task . Run ( async ( ) =>
127131 {
128132 try
129133 {
130- await _consoleProgressSync . WaitAsync ( ) ;
134+ await _consolePrintLock . WaitAsync ( ) ;
131135
132- await Task . Delay ( 1000 ) ;
133136 var index = 0 ;
134- var isDownloading = await _browserDownloadSync . IsLockAlreadyAcquiredAsync ( ) ;
135- while ( isDownloading )
137+ while ( await _browserDownloadLock . IsLockAlreadyAcquiredAsync ( ) ) //browser is downloading
136138 {
137139 Console . Write ( $ "Browser is downloading, please wait{ new string ( '.' , index + 1 ) , - 5 } ") ;
138140 Console . SetCursorPosition ( 0 , Console . CursorTop ) ;
@@ -144,7 +146,7 @@ public static async Task EnsureBrowserDownloadedAsync(bool silent = false)
144146 }
145147 finally
146148 {
147- _consoleProgressSync . Release ( ) ;
149+ _consolePrintLock . Release ( ) ;
148150 }
149151 } ) ) ;
150152 }
0 commit comments