I tried to apply some of these settings. Some work, some don't.
//_Layout.cshtml
@using Microsoft.AspNetCore.Components.Web
@namespace BlazorApp1.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="~/" />
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
<link href="css/site.css" rel="stylesheet" />
<link href="BlazorApp1.styles.css" rel="stylesheet" />
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
</head>
<body>
@RenderBody()
<div id="blazor-error-ui">
<environment include="Staging,Production">
An error has occurred. This application may no longer respond until reloaded.
</environment>
<environment include="Development">
An unhandled exception has occurred. See browser dev tools for details.
</environment>
<a href="" class="reload">Reload</a>
<a class="dismiss"></a>
</div>
<environment include="Development">
<script src="_framework/blazor.server.js" autostart="false"></script>
<script>
document.addEventListener("DOMContentLoaded", function () {
Blazor.start({
configureSignalR: function (builder) {
let c = builder.build();
c.serverTimeoutInMilliseconds = 5000;
c.keepAliveIntervalInMilliseconds = 2500;
builder.build = () => {
return c;
};
},
reconnectionOptions: {
retryIntervalMilliseconds: 500,
maxRetries: 25
}
});
});
</script>
</environment>
<environment exclude="Development">
<script src="_framework/blazor.server.js"></script>
</environment>
</body>
</html>
[above Code edited to reflect comment.]
Note: the important part is the 2nd script
tag, which follows <script src="_framework/blazor.server.js" autostart="false"></script>
. Also note, that in this variation I use the DOMContentLoaded
event, but some examples simply omit this and only use Blazor.start(...)
, which IMHO both are valid, and I did not notice any difference so far.
Sidenote: Some sources say that the JS for Starting Blazor should/can be placed in _Host.cshtml. I assume from the project structure, that both styles are valid options. (_Host.cshtml is simply the @RenderBody and holds the App-component, which should result in roughly the same final DOM).
and
//program.cs
builder.Services.AddServerSideBlazor(options =>
{
options.DetailedErrors = true;
}).AddHubOptions(options =>
{
options.ClientTimeoutInterval = TimeSpan.FromSeconds(30);
options.EnableDetailedErrors = true;
options.HandshakeTimeout = TimeSpan.FromSeconds(15);
options.KeepAliveInterval = TimeSpan.FromSeconds(1);
//options.MaximumParallelInvocationsPerClient = 1;
//options.MaximumReceiveMessageSize = 32 * 1024;
//options.StreamBufferCapacity = 10;
});
Test when clicking "PAUSE" in VS Debug-Mode:
When I pause the App in VS, the reconnect UI shows:
Attempting to reconnect to the server: 6 of 35
But each attempt takes over 1:30 minutes (not always the same time)!
Another Test showed: one attempt ~40sec another over ~90sec.
Another Test showed: the first few (5) took a longer time but then for the remaining it was ~7sec consistently.
Specifically maxRetries: 35
works as expected every time, but it seems to me retryIntervalMilliseconds: 1000
does not work at all.
Why is that, what can I do that each attempt takes the same time, and how can I reliably set it up? Maybe a working example?
Specifically, I'd like to have a setup where each attempt really runs quickly (<1000ms) and a lot of them.
Are there some min values maybe, if so, where is the documentation on that?
[Edit]:
I ran more tests with a remote PC: With very different results for the time taken of each attempt, depending on how the connection is disturbed.
- Firewall (all always 20s)
- Wi-Fi (first one 10s then 0.5s)
- Browser offline mode (all always 0.5s)
- VS Pause / Stop (inconsistent ~40s, ~90s)