问题
Alright i am using System.Threading.Timer objects to regularly fire events
Q1: As far as i understood it starts new tasks like Task.Factory.StartNew am i correct ?
Here how i use example System.Threading.Timer object
private static Timer _timer;
_timer = new Timer(checkWaitingUrls, null, PublicSettings.irTimers_Delayed_Start_MiliSeconds, howManySeconds * 1000);
Now i can handle unexpected errors at Task.Factory.StartNew like below
Task myTask = Task.Factory.StartNew(() =>
{
process_Given_Page(drwToProcess);
});
myTask.ContinueWith(t => ErrorLogger.LogError
("error " + t), TaskContinuationOptions.OnlyOnFaulted);
Q2: How can i handle System.Threading.Timer callback tasks when an error happened so the application wouldn't crash and timer continues to work?
I don't want to code complete try catch event inside the timer callback function
Ty very much for answers
c# .net 4.5 WPF
Edit I found the answer that use System.Timers.Timer and it will swallow such errors without letting you know however you can't log them
来源:https://stackoverflow.com/questions/25417084/system-threading-timer-working-logic-and-if-an-unexpected-error-happens-how-to-h