@@ -16,11 +16,7 @@ internal class LiveReloadingContext
16
16
// Keep in sync with the const in Microsoft.AspNetCore.Blazor.Build's AppBuilder.cs
17
17
private const string BlazorBuildCompletedSignalFile = "__blazorBuildCompleted" ;
18
18
19
- // If some external automated process is writing multiple files to wwwroot,
20
- // you probably want to wait until they've all been written before reloading.
21
- // Pausing by 500 milliseconds is a crude effort - we might need a different
22
- // mechanism (e.g., waiting until writes have stopped by 500ms).
23
- private const int WebRootUpdateDelayMilliseconds = 500 ; // TODO: REMOVE THIS
19
+ // These strings are in the format needed by EventSource
24
20
private const string heartbeatMessage = "data: alive\n \n " ;
25
21
private const string reloadMessage = "data: reload\n \n " ;
26
22
@@ -84,7 +80,7 @@ private void CreateFileSystemWatchers(BlazorConfig config)
84
80
distFileWatcher . Deleted += ( sender , eventArgs ) => {
85
81
if ( eventArgs . Name . Equals ( BlazorBuildCompletedSignalFile , StringComparison . Ordinal ) )
86
82
{
87
- RequestReload ( 0 ) ;
83
+ RequestReload ( ) ;
88
84
}
89
85
} ;
90
86
distFileWatcher . EnableRaisingEvents = true ;
@@ -97,27 +93,24 @@ private void CreateFileSystemWatchers(BlazorConfig config)
97
93
if ( ! string . IsNullOrEmpty ( config . WebRootPath ) )
98
94
{
99
95
var webRootWatcher = new FileSystemWatcher ( config . WebRootPath ) ;
100
- webRootWatcher . Deleted += ( sender , evtArgs ) => RequestReload ( WebRootUpdateDelayMilliseconds ) ;
101
- webRootWatcher . Created += ( sender , evtArgs ) => RequestReload ( WebRootUpdateDelayMilliseconds ) ;
102
- webRootWatcher . Changed += ( sender , evtArgs ) => RequestReload ( WebRootUpdateDelayMilliseconds ) ;
103
- webRootWatcher . Renamed += ( sender , evtArgs ) => RequestReload ( WebRootUpdateDelayMilliseconds ) ;
96
+ webRootWatcher . Deleted += ( sender , evtArgs ) => RequestReload ( ) ;
97
+ webRootWatcher . Created += ( sender , evtArgs ) => RequestReload ( ) ;
98
+ webRootWatcher . Changed += ( sender , evtArgs ) => RequestReload ( ) ;
99
+ webRootWatcher . Renamed += ( sender , evtArgs ) => RequestReload ( ) ;
104
100
webRootWatcher . EnableRaisingEvents = true ;
105
101
_pinnedWatchers . Add ( webRootWatcher ) ;
106
102
}
107
103
}
108
104
109
- private void RequestReload ( int delayMilliseconds )
105
+ private void RequestReload ( )
110
106
{
111
- Task . Delay ( delayMilliseconds ) . ContinueWith ( _ =>
107
+ lock ( _currentReloadListenerLock )
112
108
{
113
- lock ( _currentReloadListenerLock )
114
- {
115
- // Lock just to be sure two threads don't assign different new CTSs, of which
116
- // only one would later get cancelled.
117
- _currentReloadListener . Cancel ( ) ;
118
- _currentReloadListener = new CancellationTokenSource ( ) ;
119
- }
120
- } ) ;
109
+ // Lock just to be sure two threads don't assign different new CTSs, of which
110
+ // only one would later get cancelled.
111
+ _currentReloadListener . Cancel ( ) ;
112
+ _currentReloadListener = new CancellationTokenSource ( ) ;
113
+ }
121
114
}
122
115
}
123
116
}
0 commit comments