Refactor StopApplication example in Hosting topic (#5485)

pull/5499/head
Luke Latham 2018-02-20 11:31:44 -06:00 committed by Scott Addie
parent 5399bf3923
commit 6b1444c308
1 changed files with 4 additions and 13 deletions

View File

@ -860,28 +860,19 @@ public class Startup
}
```
[StopApplication](/dotnet/api/microsoft.aspnetcore.hosting.iapplicationlifetime.stopapplication) requests termination of the app. The following [Razor Pages](xref:mvc/razor-pages/index) page model class uses `StopApplication` to gracefully shutdown an app. The `OnPostShutdown` method executes after the **Shutdown** button in the UI is selected:
```cshtml
<button type="submit" asp-page-handler="Shutdown" class="btn btn-default">Shutdown</button>
```
[StopApplication](/dotnet/api/microsoft.aspnetcore.hosting.iapplicationlifetime.stopapplication) requests termination of the app. The following class uses `StopApplication` to gracefully shutdown an app when the class's `Shutdown` method is called:
```csharp
public class IndexModel : PageModel
public class MyClass
{
private readonly IApplicationLifetime _appLifetime;
public IndexModel(IApplicationLifetime appLifetime)
public MyClass(IApplicationLifetime appLifetime)
{
_appLifetime = appLifetime;
}
public void OnGet()
{
...
}
public void OnPostShutdown()
public void Shutdown()
{
_appLifetime.StopApplication();
}