//event EventHandler<EventMessage> onListBoxItemAdded; public Form1() { InitializeComponent(); _handler = new HandlerForImg(); // handlerController = new HandleForImgController(_handler, 1); handlerController = new HandleForImgController(); for (int i = 1; i < 101; i++) { cmbQuality.Items.Add(i.ToString()); } cmbQuality.SelectedIndex = 59; }
private DealResult DoSomeWork(List <string> srcColletion, CancellationToken token, string outPutPath, string InPath, int dHeight, int dWidth, int flag) { string errMsg = ""; LogContext log = new LogContext(); string path = System.IO.Directory.GetCurrentDirectory(); DateTime CurrTime = DateTime.Now; DealResult res = new DealResult(); string strPath = path + "\\HandDataLog\\" + CurrTime.Year + "-" + CurrTime.Month + "\\" + CurrTime.Day + ".txt"; Stopwatch st = new Stopwatch(); st.Start(); string diFile = ""; foreach (string siFile in srcColletion) { // FileInfo fi = new FileInfo(siFile); diFile = siFile.Replace(InPath, outPutPath); if (!Directory.Exists(Path.GetDirectoryName(diFile))) { Directory.CreateDirectory(Path.GetDirectoryName(diFile)); } if (token.IsCancellationRequested) { showMsg(this, new EventMessage { msg = "线程" + Task.CurrentId + "任务已经取消!" }); //"线程"+id.ToString()+ onAllTaskCompleteHandler(this, new EventMessage { msg = "线程" + Thread.CurrentThread.ManagedThreadId + "任务被终止!" }); //"线程"+id.ToString()+ break; } bool r = HandlerForImg.GetPicThumbnail(siFile, diFile, ref errMsg, dHeight, dWidth, flag); if (!r) { res.failCount += 1; showMsg(this, new EventMessage { msg = "压缩不成功,路径名:" + siFile + "错误信息:" + errMsg }); log.AddLogInfo(strPath, "压缩不成功,路径名:" + siFile + "错误信息:" + errMsg, true); } showMsg(this, new EventMessage { msg = "压缩成功,输出路径:" + diFile }); //log.AddLogInfo(strPath, "压缩成功,输出路径:" + diFile, true); res.sucessCount += 1; } st.Stop(); res.totalTime += st.ElapsedMilliseconds / 1000; //Thread.Sleep(1000); return(res); }