using Ease.Core.Utility; using System; using System.Threading; namespace HRM.UI { /// /// Runs a mail batch away from the request thread. /// /// Sending to a thousand employees takes minutes; holding the HTTP request /// open for that long is what made the old screen warn people about "around /// 10 minutes". Because the batch and all of its recipient rows are written /// to MasterEmailLog before this is called, the browser can be told the /// batch id immediately and simply watch the row - nothing depends on the /// request still being alive. /// /// The thread is deliberately non-background (the same choice MailSender's /// own ThreadSendMail makes) so that a recycle waits for the mails already /// in flight instead of cutting them off mid-batch. Anything that escapes /// goes to ExceptionLog; it can never surface as an unhandled exception, /// which on a background thread would take the whole worker process down. /// public static class EmailLogBackgroundRunner { public static void Run(Action work) { if (work == null) { return; } Thread worker = new Thread(() => { try { work(); } catch (Exception ex) { ExceptionLog.Write(ex); } }); worker.IsBackground = false; worker.Start(); } } }