/// <summary> /// 子线程执行方法 创建ID /// </summary> /// <param name="obj"></param> public static void TestFun(object obj) { int thredid = Convert.ToInt32(obj); var _scoubnt = ((thredid - 1) * _thredworkcount); //子线程执行开始时间 DateTime dt1 = DateTime.Now; Console.WriteLine(string.Format(" 线程 {0} 任务执行中...", thredid)); for (int i = 0; i < _thredworkcount; i++) { try { var _id = _snowflake.nextId(); _worksdata[_scoubnt + i] = _id; //Console.WriteLine(string.Format(" 线程 {0} 生成ID:{1} 二进制:{2}", thredid, _id, Convert.ToString(_id, 2).PadLeft(64, '0'))); } catch (Exception e) { Console.WriteLine(string.Format(" 线程 {0} 生成ID异常:{1}", thredid, e.Message)); break; } } Console.WriteLine(string.Format(" 线程 {0} 执行 {1} 次ID生成 任务完毕,耗时:{2} 秒 ", thredid, _thredworkcount, (DateTime.Now - dt1).TotalSeconds)); _thredsokcount++; //任务执行完毕 if (_thredsokcount == _thredscount) { Console.WriteLine(string.Format(" \r\n 所有线程执行完毕,总耗时:{0} 秒", (DateTime.Now - _workstarttime).TotalSeconds)); Console.WriteLine(string.Format(" \r\n 开始比较生成ID数据的重复项...")); var result = Repeat(_worksdata); Console.WriteLine(string.Format(" 生成 {0} 条ID 里面包含 {1} 条重复ID ", _thredscount * _thredworkcount, result.Count())); foreach (var item in result) { Console.WriteLine(string.Format(" 重复ID:{0}", item)); } } }
public void resultJoin(string imgName, bool isFront, double scale, Rectangle scaleRect, bbox_t_container boxlist, List <string> names, Point startPoint) { Snowflake snowflake = new Snowflake(2); if (boxlist.bboxlist.Length > 0) { for (int i = 0; i < boxlist.bboxlist.Length; i++) { if (boxlist.bboxlist[i].h == 0) { break; } else { string id = imgName.Replace(".jpg", "") + "(" + snowflake.nextId().ToString() + ")"; bbox_t bbox = boxlist.bboxlist[i]; bbox.x = (uint)((bbox.x + startPoint.X) * scale) + (uint)scaleRect.X; // + (uint)scaleRect.X; bbox.y = (uint)((bbox.y + startPoint.Y) * scale) + (uint)scaleRect.Y; // + (uint)scaleRect.Y; bbox.w = (uint)(bbox.w * scale); bbox.h = (uint)(bbox.h * scale); Result result = new Result() { Id = id, IsBack = Convert.ToInt32(!isFront), score = bbox.prob, PcbId = nowPcb.Id, Area = "", Region = bbox.x + "," + bbox.y + "," + bbox.w + "," + bbox.h, NgType = names[(int)bbox.obj_id], PartImagePath = id + ".jpg", CreateTime = DateTime.Now, }; lock (nowPcb.results) { nowPcb.results.Add(result); } } } } }