11

I need to run long running background tasks in my asp.net core application. I know of Azure Webjobs and other out of process techniques but I'd rather keep the solution simple and runs those tasks directly in the asp.net core process. I use Kestrel and the application is hosted in IIS.

I understand that IIS will occasionally recycle the IIS process. Will it also recycle the asp.net core process?

Clement
  • 3,990
  • 4
  • 43
  • 44

3 Answers3

4

Asp.Net Core < 2.2

Asp.net Core runs in a separate process dotnet.exe even when it is hosted in IIS. But it doesn't mean that it runs as an independent process. IIS still responsible for Asp.net core process (dotnet.exe) life cycle through the AspNetCoreModule.

So, answer is yes, IIS will also recycle the asp.net core process

Asp.Net Core >= 2.2

Asp.Net Core 2.2 has in-process hosting support on IIS in addition to out-of-process hosting model that was before. It seems it is just an optimization that allows to avoid the additional cost of reverse-proxying requests over to a separate dotnet process. IIS will recycle application pool with Asp.net Core application

AlbertK
  • 11,841
  • 5
  • 40
  • 36
1

I have do a experiment use ' IApplicationLifetime applicationLifetime ' like aspnet Golbal.aspx

When the iis application recycle , the registerd 'ApplicationStopping' be triggered.

SO i will belive the https://github.com/aspnet/KestrelHttpServer/issues/1040#issuecomment-267506588

Julian89757
  • 160
  • 1
  • 4
-2

Nope, It would not. IIS application pool only takes care of w3wp.exe process.

ASP.NET Core is hosted by Kestrel process, and IIS is just a reverse proxy in front of it.

Lex Li
  • 60,503
  • 9
  • 116
  • 147
  • Kestrel process will be spawned by apppool user. What happens during recycle? Doesn't iis kill all processes of apppool user during recycle? – pepo Dec 16 '16 at 12:37
  • @pepo you can do some experiments. I believe Kestrel process remains. IIS does not "kill all processes of apppool user", never. It just replaces worker processes (w3wp.exe). – Lex Li Dec 16 '16 at 12:57
  • 1
    Hmm I don't know about that: https://github.com/aspnet/KestrelHttpServer/issues/1040#issuecomment-267506588 – Clement Dec 18 '16 at 23:25
  • @Clement I believe David omitted the details behind. If we split carefully what is IIS and what is ASP.NET Core, then IIS has no idea what is Kestrel at all. Based on his words, I can only guess that ASP.NET Core module plugged in IIS worker process hijacks in the recycling steps, and sends a signal to Kestrel to exit. Luckily the module is fully open source on GitHub, so we might be able to check the code and see how. – Lex Li Dec 19 '16 at 02:15
  • 1
    Observable results would seem to indicate the contrary (at least with .net-core 1.1) - i.e. the dotnet process is shut down. – SpruceMoose Nov 27 '17 at 13:50