Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

IApplicationLifetime ApplicationStopping does not trigger when you press ctl+c from the command line #296

@jsacapdev

Description

@jsacapdev

Possibly related to #151.

In the following code:

using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.Framework.DependencyInjection;
using System;

namespace TestAppShutdownWebApi
{
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
        }

        public void Configure(IApplicationBuilder app, IApplicationLifetime lifetime)
        {
            lifetime.ApplicationStopping.Register(OnStopping);

            app.UseMvc();
        }

        public void OnStopping()
        {
            Console.WriteLine("OnStopping");
        }
    }
}

...the OnStopping event is not raised.

The following code works.

using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
using Microsoft.Framework.DependencyInjection;
using System;

namespace TestAppShutdownWebApi
{
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
        }

        public void Configure(IApplicationBuilder app, IApplicationLifetime lifetime)
        {
            lifetime.ApplicationStopping.Register(OnStopping);
        }

        public void OnStopping()
        {
            Console.WriteLine("OnStopping");
        }
    }
}

This is the case for Microsoft.AspNet.Server.WebListener or Kestrel.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions