I’m doing a Fire-and-Forget method invocation like this.
BackgroundJob.Enqueue(() => SendEmail(name));
I want to fail the job inside the SendEmail() method.
Because since all the probable exceptions are handled in my code, even if an exception occurs in the job method, the result of the job will be ‘Successful’. Because the exception is handled.
How to force to Fail a Job?. According to the above topic we have to throw an exception in order to fail a job. Is there any other way to do this?
I have a special situation here, I’m using a WPF app, I’m running Hangfire server in the WPF app like a Windows Service or Console app,
I can queue the jobs and run but when a job is failure by an exception anything like loss connection to internet or something the app crash, I can’t catch the exception because I tried to mark the job as failure but this unhandled exception and the app crash and close, I tried to use AttempRetries attribute but Hangfire is not able to catch the exception