private static Thread m_threadWatch = null; // 用户工作的线程 public void AddWork(MSOfficeThreadWork work) { lock (m_worksQueue) { m_worksQueue.Enqueue(work); } }
public void AddRegularloadWork(int categoryId) { // 会签单信息已经完成,直接生成会签单信息 MSOfficeThreadWork work = new MSOfficeThreadWork { WorkKind = WORK_KIND.CREATE_REGULARLOAD_REQUEST, CategoryId = categoryId, }; lock (m_worksQueue) { m_worksQueue.Enqueue(work); } }
/// <summary> /// 向工作队列中添加一个会签单 /// </summary> /// <param name="contractId"></param> public void AddContractWork(string contractId) { // 会签单信息已经完成,直接生成会签单信息 MSOfficeThreadWork work = new MSOfficeThreadWork { WorkKind = WORK_KIND.CREATE_CONTRACT_REQUEST, ContractId = contractId }; lock (m_worksQueue) { m_worksQueue.Enqueue(work); } }
/// <summary> /// 向工作队列中添加一个统计信息 /// 任务为统计当前年份year, 当前类Category别下的会签单信息 /// </summary> /// <param name="year"></param> /// <param name="categoryId"></param> public void AddStatisticWork(int year, int categoryId) { // 会签单信息已经完成,直接生成会签单信息 MSOfficeThreadWork work = new MSOfficeThreadWork { WorkKind = WORK_KIND.CREATE_STATISTC_REQUEST, Year = year, CategoryId = categoryId, }; lock (m_worksQueue) { m_worksQueue.Enqueue(work); } }
public void Work() { while (true) { //判断队列中是否存在待写入的日志 if (m_worksQueue.Count > 0) { MSOfficeThreadWork work = null; // 首先从工作队列中取出一个信息 lock (m_worksQueue) { work = m_worksQueue.Dequeue(); } if (work != null) { // 开始工作 switch (work.WorkKind) { /// 需要生成会签单文档WORD case WORK_KIND.CREATE_CONTRACT_REQUEST: MSWordTools.CreateHDJContractWork(work.ContractId); // 生成会签单信息 break; /// 需要生成统计文档EXCEL case WORK_KIND.CREATE_STATISTC_REQUEST: MSExcelTools.StatisticHSYearCategory(work.Year, work.CategoryId); //MSExcelTools.StatisticYearCategory(work.Year, work.CategoryId); break; case WORK_KIND.CREATE_REGULARLOAD_REQUEST: MSExcelTools.CreateRegularloadTemplateFile(work.CategoryId); break; case WORK_KIND.UPLOAD_REGULARLOAD_REQUEST: MSExcelTools.UploadRegularLoad(work.Year, work.CategoryId); break; } } } else { Thread.Sleep(10000); } } }
/// <summary> /// 向工作队列中添加一个统计信息 /// 每当完成一个单子之后其实就可以统计这个单子所属的工作量的信息 /// 任务为统计当前年份year, 当前类Category别下的会签单信息 /// </summary> /// <param name="contractId"></param> public void AddStatisticWork(string contractId) { // 会签单信息已经完成,直接生成会签单信息 int year = DALHDJContract.GetYearFromContractId(contractId); // 从编号中取出年份信息 // 此处其实有性能的缺失 string categoryShortCall = DALHDJContract.GetCatgoryShortCallFromContractId(contractId).ToString(); // 从会签单中取出简称 ContractCategory category = DALContractIdCategory.GetCategory(categoryShortCall); MSOfficeThreadWork work = new MSOfficeThreadWork { WorkKind = WORK_KIND.CREATE_STATISTC_REQUEST, Year = year, CategoryId = category.Id, }; lock (m_worksQueue) { m_worksQueue.Enqueue(work); } }