private void OnRaiseReporting(PaperInfoFinishArgs e) { ReportEventHandler handler = OneFinished; if (handler != null) { handler(this, e); } }
private void OnRaiseFinished(object sender, PaperInfoFinishArgs e) { FinishedEventHandler handler = ReportFinished; if (handler != null) { handler(sender, e); } }
private void PaperHandler_ReportFinished(object sender, PaperInfoFinishArgs e) { try { //one finished if (e.Error != null) { //异常出错 lock (m_ErrorNumLock) { ErrorNum++; } SLogger.Instance.Writer(SLogLevel.Error, e.Error.Code + e.Error.Msg); return; } UserPaperDto u = e.UPaper; string uName = u.UserName; lock (m_HandledNumLock) { //执行的成功次数 HandledNum++; } PaperInfoFinishArgs arg = new PaperInfoFinishArgs() { UPaper = u }; OnRaiseReporting(arg); //to remove if (m_HandlerDic.ContainsKey(uName)) { m_HandlerDic.Remove(uName); } } catch (Exception ex) { SLogger.Instance.Writer(SLogLevel.Error, e.Error.Code + e.Error.Msg); } finally { //todo next 轮询 RunOneTask(); lock (m_FinishLock) { if (IsCompleted && !m_OneFinished) { m_OneFinished = true; m_State = JobState.End; //finished Console.WriteLine("All Finished!"); OnRaiseFinished(new EventArgs()); } } } }
private void RunTask() { //int num = DefaultThreadNum < m_TaskStack.Count ? DefaultThreadNum : m_TaskStack.Count; int num = m_TaskQueue.Count; if (num == 0) { sw.Stop(); //finished report //m_Groups UserPaper.SpendTime = (int)sw.ElapsedMilliseconds / 1000; UserPaper.GroupData = m_Groups; UserPaper.GroupNum = m_Groups.Count; PaperInfoFinishArgs args = new PaperInfoFinishArgs() { UPaper = UserPaper }; OnRaiseFinished(this, args); Console.WriteLine(string.Format("共分{0}组", m_Groups.Count)); return; } List <FileDto> datas = new List <FileDto>(); for (int i = 0; i < num; i++) { FileDto t; if (m_TaskQueue.TryDequeue(out t)) { datas.Add(t); } } if (datas.Count >= 1) { Task ts = new Task(() => Run(datas)); ts.Start(); } }