public static void Main() { //新建ManualResetEvent对象并且初始化为无信号状态 ManualResetEvent eventX = new ManualResetEvent(false); ThreadPool.SetMaxThreads(3, 3); for (int i = 0; i < 15; i++) { thr t = new thr(15, eventX); ThreadPool.QueueUserWorkItem(new WaitCallback(t.ThreadProc), i); } //等待事件的完成,即线程调用ManualResetEvent.Set()方法 //eventX.WaitOne 阻止当前线程,直到当前 WaitHandle 收到信号为止。 // eventX.WaitOne(Timeout.Infinite, true); Console.WriteLine("断点测试"); Thread.Sleep(10000); Console.WriteLine("运行结束"); }
/// <summary> /// 开始进行Excel表格的数据解析 /// </summary> /// <param name="_config_str"></param> /// <returns></returns> public static bool BeginToExportExcels(string _config_str) { //线程池设置 ThreadPool.SetMaxThreads(3, 3); string[] excel_config_list; if (_config_str != "") { string _DataSavePath = ApplicationConfig.ExcelsFilePath + "\\ExportDatas"; //如果不存在就创建file文件夹 if (Directory.Exists(_DataSavePath) == false) { Directory.CreateDirectory(_DataSavePath); } else { //先清空文件夹 DirectoryInfo dInfo = new DirectoryInfo(_DataSavePath); FileInfo[] files = dInfo.GetFiles(); foreach (FileInfo file in files) { File.Delete(file.FullName); } } //将换行符替换为"\"分割 _config_str = _config_str.Replace("\r\n", "\\"); excel_config_list = _config_str.Split('\\'); ApplicationConfig.Excel_files_num = excel_config_list.Length; for (int i = 0; i < excel_config_list.Length; i++) { /* * //第一个符号为"#"的是注释内容,不做解析 * if (excel_config_list[i].Substring(0, 1) == "#") * { * Console.Write("注释内容:"+excel_config_list[i]); * } * else * { * string[] config_sheet = excel_config_list[i].Split(','); * ExcelHelper myExlHelper = new ExcelHelper(Form1.ExcelsFilePath+"\\"+config_sheet[0]); * if (config_sheet[0] == "cardproperty.xls") * { * string result = myExlHelper.ExcelToDataTable(Int32.Parse(config_sheet[1]), Int32.Parse(config_sheet[2]), Int32.Parse(config_sheet[3]),config_sheet[4], true); * Console.Write("cardproperty.xls"); * } * }*/ thr t = new thr(); ThreadPool.QueueUserWorkItem(new WaitCallback(t.AnalyseAndBuildFiles), excel_config_list[i]); } return(false); } else { return(true); } }
static void Main(string[] args) { ManualResetEvent eventX = new ManualResetEvent(false); ThreadPool.SetMaxThreads(3, 3); thr t = new thr(15, eventX); for (int i = 0; i < 15; i++) { ThreadPool.QueueUserWorkItem(new WaitCallback(t.ThreadProc), i); } eventX.WaitOne(Timeout.Infinite, true); Console.WriteLine("断点测试"); Thread.Sleep(1000); Console.WriteLine("运行结束"); Console.ReadKey(); }