I' m working on a desktop application with .NET 6 and WinUI3. This application keeps tracking data changes in PLC and transfers real time data to my server and dashboard.
My server is cloud based. Using the server as a message hub to transmit the data will cause unnecessary delay and performance occupation. That's why I want to host a signalR server in my desktop application so that it could work as a lightweight web server.
I found Tutorial: SignalR Self-Host but it's not for .NET Framework 4.x. Can I still host a SignalR server in my desktop application with Asp.Net Core SignalR?
I'm a non-native English speaker. There might be some grammatical mistakes in my description and I'm sorry for that.
You can most probably leverage the background services offered in all net core applications.
signalr/background-services
Setting it up, can be as simple as this:
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddSignalR();
services.AddHostedService<Worker>();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<ClockHub>("/hubs/clock");
});
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With