2016-09-12 30 views
0

我在我的asp.net核心应用程序(framework net46)中运行我的AKKA.NET演员系统。我通过运行“DOTNET跑”运行从命令提示符的web的应用程序,当我尝试使用Ctrl-C退出它,我得到以下输出和提示挂在那儿:AKKA.NET演员系统在asp.net核心应用程序中未正确关闭

   c:\D3\>19:05:33.7024266 ENV=d0 Sdm.Web DEBUG Akka.Actor.Internal.ActorSystemImpl Disposing system 
      19:05:33.7084292 ENV=d0 Sdm.Web DEBUG Akka.Actor.Internal.ActorSystemImpl System shutdown initiated 
      [DEBUG][12/09/16 19:05:33][Thread 0023][EventStream] subscribing [akka://all-systems/] to channel Akka.Event.Debug 
      19:05:33.7134423 ENV=d0 Sdm.Web DEBUG Akka.Actor.GuardianActor Stopping 
      [DEBUG][12/09/16 19:05:33][Thread 0023][EventStream] subscribing [akka://all-systems/] to channel Akka.Event.Info 
      [DEBUG][12/09/16 19:05:33][Thread 0023][EventStream] subscribing [akka://all-systems/] to channel Akka.Event.Warning 
      [DEBUG][12/09/16 19:05:33][Thread 0023][EventStream] subscribing [akka://all-systems/] to channel Akka.Event.Error 

如果我打另一个CTRL -c退出。但这看起来不正确。我使用依赖注入容器来管理角色系统(单例作用域)的生存时间,所以我假设容器实际上是试图在应用程序关闭时处理对象。

有人可以提出什么可能是错的?

回答

1

如果需要正常关机,则需要直接停止Akka.NET Actors。这样做使用由ASP.NET提供的核心应用程序关闭事件通过IApplicationLifetime接口:

CancellationToken ApplicationStopping { get; } 
CancellationToken ApplicationStopped { get; } 

获得的IApplicationLifetime一个实例可以Startup.cs过程中Configure方法来完成:

protected void DisposeResources() 
{ 
    //Cleanup stuff when the app is shutting down 
} 

public void Configure(IApplicationBuilder app, IApplicationLifetime applicationLifetime) 
{ 
    //register the application shutdown handler 
    applicationLifetime.ApplicationStopping.Register(DisposeResources); 
} 

更多细节见文章ASP.NET Core application shutdown events 和这个SO问题Kestrel shutdown function in Startup.cs in ASP.NET Core

+0

伟大的thx。将尝试一下,让你知道它是如何去。 –