private void RetryCallback(IAsyncResult ar) { Interlocked.Decrement(ref this.retryingCount); TaskBag <TTask> asyncState = (TaskBag <TTask>)ar.AsyncState; bool flag = false; Exception exception = null; try { flag = this.action.EndInvoke(ar); } catch (Exception exception2) { exception = exception2; } if (flag) { this.eventSafeTrigger.Action <TTask, DateTime, int>("TaskSucceed", this.TaskSucceed, asyncState.Task, asyncState.AddedTime, 0); } else { asyncState.LastActionTime = DateTime.Now; this.retryList.Add(asyncState); this.eventSafeTrigger.Action <TTask, Exception>("TaskFailed", this.TaskFailed, asyncState.Task, exception); } }
protected virtual void TaskWorker() { while (!this.disposed) { if (this.taskQueue.Count == 0) { Thread.Sleep(10); } else { TaskBag <TTask> t = this.taskQueue.Dequeue(); bool flag = false; Exception exception = null; try { flag = this.action(t.Task); } catch (Exception exception2) { exception = exception2; } if (flag) { this.eventSafeTrigger.Action <TTask, DateTime, int>("TaskSucceed", this.TaskSucceed, t.Task, t.AddedTime, 0); } else { t.LastActionTime = DateTime.Now; this.retryList.Add(t); this.eventSafeTrigger.Action <TTask, Exception>("TaskFailed", this.TaskFailed, t.Task, exception); } } } }
protected virtual void RetryWorker() { while (!this.disposed) { if (this.retryList.Count == 0) { Thread.Sleep(0x3e8); } else { List <TaskBag <TTask> > list = new List <TaskBag <TTask> >(); List <TaskBag <TTask> > all = this.retryList.GetAll(); for (int i = 0; i < all.Count; i++) { TaskBag <TTask> item = all[i]; TimeSpan span = (TimeSpan)(DateTime.Now - item.LastActionTime); if (span.TotalSeconds >= item.SpanInSecsIfRetry) { list.Add(item); } } foreach (TaskBag <TTask> bag in list) { this.retryList.Remove(bag); try { Interlocked.Increment(ref this.retryingCount); bag.RetryCount++; this.action.BeginInvoke(bag.Task, new AsyncCallback(this.RetryCallback), bag); } catch (Exception exception) { Interlocked.Decrement(ref this.retryingCount); bag.LastActionTime = DateTime.Now; this.retryList.Add(bag); this.eventSafeTrigger.Action <TTask, Exception>("TaskFailed", this.TaskFailed, bag.Task, exception); } } } } }