Base solution for your next web application
Open Closed

How to kill a background job? #7366


User avatar
0
timmackey created

When debugging a background job ... (https://aspnetboilerplate.com/Pages/Documents/Background-Jobs-And-Workers) ...If debug execution is terminated (i.e. at a breakpoint) before the job finishes, the background job attempts to continue where it left off when the debugger is started again.

How can I find the background job in the Task Manager and manually kill it? Or is there another way to kill the background job?

Also, how can I kill a running background job programmatically?


5 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    the background job attempts to continue where it left off when the debugger is started again.

    This is normal.

    When you are debugging it, you can clear all background tasks when the application is launched.

    Use IRepository<BackgroundJobInfo, long> to delete all task information.

  • User Avatar
    0
    timmackey created

    This answer is too cryptic. Please provide a more comprehensive answer.

  • User Avatar
    0
    alper created
    Support Team

    hi tim,

    do you mean to terminate the process of the background job? if so, open CMD and write tskill your-exe-file-name https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/tskill

  • User Avatar
    0
    maliming created
    Support Team

    How can I find the background job in the Task Manager and manually kill it?

    You can inject the IBackgroundJobStore interface and call the GetWaitingJobsAsync method. Of course, you can also use IRepository<BackgroundJobInfo, long> to get more comprehensive task information, which exists in the database. Just like the implementation of BackgroundJobStore in the Abp.Zero.Common package.

    Or is there another way to kill the background job?

    You can directly empty the AbpBackgroundJobs table in the database so that all tasks will disappear.

    Also, how can I kill a running background job programmatically?

    You can use IBackgroundJobManager to delete a task, but the abp default implementation of the background task is relatively simple, if you need more advanced background task management, please consider using hangfire and other components.

    See: https://aspnetboilerplate.com/Pages/Documents/Background-Jobs-And-Workers

  • User Avatar
    1
    timmackey created

    @maliming- The code you posted (and deleted?) was very helpful, and has been incorporated into my app. It survives in the email announcement of your original reply.

    @alper- RE: tskill your-exe-file-name What is my exe file name? It's apparently not myapp-web.host.exe. What am I looking for?

    RE: the other suggestions, it may be a few days or longer before I'm able to try your suggestions. I'll post the results here when available.