I found the answer I had to use HeadlessJsTaskWorker instead of HeadlessJsTaskService now when app is closed it works