c# - Implement a watchdog for critical tasks -


i have application sends emails on scheduled times. appliction gets stuck while sending email, i'm still not sure why.

i thought implementing simple watchdog this: before application starts sending email, initializes new instance of watchdog. instance starts 1 time timer. if task completes ok - let watchdog know should stand down, , cancels timer. if timer defined period had elapsed - exit program forcefully.

i'm not sure if valid solution or more hack, , appreciate input regarding subject.

thanks, omer

it isn't such bad idea imho.

the main pitfall see here isn't technical, humane one: once watchdog operational , it's thing properly, , customers don't complain anymore, way easy "problem solved!" , forget original issue (tossing backlog @ best, marking "resolved" @ worst).

on technical side:

you may want consider isolation level of watchdog , application, , how violent watchdog's action is. minimal isolation having watchdog run on different thread (the one-time timer that). might better have email mechanism , watchdog run on different appdomains, watchdog unloads entire "email appdomain" on timeout. gives similar resolution killing process (at least under "managed" point-of-view), less violent killing process , starting again.

you should consider race conditions: watchdog's timer , email sending process racing, end in killing process after email has been sent, further result in same email being sent once again restart application (which leads poor customer experience).

as commentators say, i'd advise debug issue. you'll need work production-debugging tools , instruments such tracing, logging, production-time debuggers (like windbg), etc., allow diagnose , debug non-reproducible issue.


Comments