logo
Tags down

shadow

Asp.NET Core 2.1 HostedService - keep running on Azure


By : Clay Anderson
Date : October 15 2020, 08:10 AM
wish of those help Ok, so in the App Settings in Azure, there is a setting Always On this worked for us. :)
We also found out from Azure support, that if you are on the lowest tier in their offered packages, this is treated as a "Development" environment and will only have limited up-time. As a result, we could expect the application to go offline when we reached that limit.
code :


Share : facebook icon twitter icon

Connect asp.net core running docker on linux to Azure Storage Emulator running on Windows host


By : Adam Fessl
Date : March 29 2020, 07:55 AM
this one helps. Unfortunately The storage emulator is not a scalable storage service and does not support a large number of concurrent clients.So it might not work for your desired scenario. It is also meant to act and work locally on a machine, not on a network based env(Connecting to the host hosting the emulator). I'd recommend checking this link which showcases the differences between the Azure storage and the Emulator capabilities.
Since you mentioned that your clients run on Linux, I'd recommend using Azurite, the equivalent of Azure Emulator for Linux, it also runs in Docker. So my suggestion would be to run multiple instances locally and test the app, or use a trial credit offered by Azure to see if it's the best fit.

Proper way to register HostedService in ASP.NET Core. AddHostedService vs AddSingleton


By : user1521732
Date : March 29 2020, 07:55 AM
will help you They are similar but not completely
AddHostedService is part of Microsoft.Extensions.Hosting.Abstractions.
code :
using Microsoft.Extensions.Hosting;

namespace Microsoft.Extensions.DependencyInjection
{
    public static class ServiceCollectionHostedServiceExtensions
    {
        /// <summary>
        /// Add an <see cref="IHostedService"/> registration for the given type.
        /// </summary>
        /// <typeparam name="THostedService">An <see cref="IHostedService"/> to register.</typeparam>
        /// <param name="services">The <see cref="IServiceCollection"/> to register with.</param>
        /// <returns>The original <see cref="IServiceCollection"/>.</returns>
        public static IServiceCollection AddHostedService<THostedService>(this IServiceCollection services)
            where THostedService : class, IHostedService
            => services.AddTransient<IHostedService, THostedService>();
    }
}
public HostedServiceExecutor(ILogger<HostedServiceExecutor> logger, 
    IEnumerable<IHostedService> services) //<<-- note services collection
{
    _logger = logger;
    _services = services;
}
_applicationServiceCollection.AddSingleton<HostedServiceExecutor>();

Getting the Base URL of the application inside of the ASP.NET Core HostedService


By : user2112273
Date : March 29 2020, 07:55 AM
Hope that helps I need to obtain the base URL of the ASP.NET Core application inside of one of the HostedServices. , I have found how to obtain the address of the appllication.
code :
public void Configure(IApplicationBuilder application)
{
    var addresses = application.ServerFeatures.Get<IServerAddressesFeature>().Addresses;
}
 public static void Main(string[] args)
 {
            var builder = CreateWebHostBuilder(args);
            var webHost = builder.Build();
            var addresses = webHost.ServerFeatures.Get<IServerAddressesFeature>().Addresses;
            var address = addresses.FirstOrDefault();
            AppDomain.CurrentDomain.SetData("BaseUrl", address?? "");
            webHost.Run();
  }
string baseUrl = AppDomain.CurrentDomain.GetData("BaseUrl").ToString();

How to start HostedService in MVC Core app without http request


By : user2299753
Date : March 29 2020, 07:55 AM
Does that help When you run this using Visual Studio, you are likely using IIS Express, which isn't going to run your ASP.NET Core project until the first request is made (that's really just how IIS works by default). This applies when using the InProcess hosting-model that's new with ASP.NET Core 2.2, which I expect you must be using in order to see this issue. See this GitHub issue for more.
You can prove this theory by removing the AspNetCoreHostingModel XML element from the .csproj file that you're using to host the ASP.NET Core application (which will switch it back to the OutOfProcess mode). It looks like there's a "Hosting Model" option under "Debug" in the project properties dialog of VS2017 that you can change to "Out Of Process" if you don't want to edit the .csproj directly.

dotnet console app, using generic host, HostedService, Windows Task Scheduler stays in running state


By : James Williams
Date : March 29 2020, 07:55 AM
seems to work fine Answer based on Microsoft.Extensions.Hosting 2.2.0
This behavior is expected, due to your usage of the Generic Host:
code :
internal class MyHostedService : IHostedService
{
    private readonly IApplicationLifetime _appLifetime;

    public MyHostedService(IApplicationLifetime appLifetime)
    {
        _appLifetime = appLifetime;
    }

    public async Task StartAsync(CancellationToken cancellationToken)
    {
        await Task.Delay(1000); //your scheduled work

        _appLifetime.StopApplication();
    }

    public Task StopAsync(CancellationToken cancellationToken)
    {
        return Task.CompletedTask;
    }
}
shadow
Privacy Policy - Terms - Contact Us © voile276.org