Skip to content

Instantly share code, notes, and snippets.

@burakcanekici
Last active July 21, 2020 11:38
Show Gist options
  • Save burakcanekici/f92c6d4181750e82473e4b8c8df13ae7 to your computer and use it in GitHub Desktop.
Save burakcanekici/f92c6d4181750e82473e4b8c8df13ae7 to your computer and use it in GitHub Desktop.
[ApiController]
[Produces("application/json")]
[Route("api/[controller]/[action]")]
public class MyController : Controller {
...
private readonly MyBackgroundService _myBackgroundService;
public MyController(HostedService hostedService)
{
...
_myBackgroundService = hostedService as MyBackgroundService;
...
}
[HttpPost]
public async Task<IActionResult> StartTask()
{
...
await _myBackgroundService.StartAsync(new System.Threading.CancellationToken());
...
}
[HttpPost]
public async Task<IActionResult> StopTask()
{
...
await _myBackgroundService.StopAsync(new System.Threading.CancellationToken());
...
}
}
@burakcanekici
Copy link
Author

~be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment