//显示需要修改的发布规则的配置信息 private void displayConfig() { mySqlDB myDB = new mySqlDB(_coConnString); string sResult = ""; int counts = 0; string sql = @"select * from pub_config where id='" + _pubID.ToString() + "'"; List <Dictionary <string, object> > pubConfigRecords = myDB.GetRecords(sql, ref sResult, ref counts); if (sResult == mySqlDB.SUCCESS) { Dictionary <string, object> pubConfig = pubConfigRecords[0]; tboxPubName.Text = pubConfig["pub_name"].ToString(); tboxPubNums.Text = pubConfig["pub_nums"].ToString(); tboxCoTypeid.Text = pubConfig["co_typeid"].ToString(); tboxCoTypename.Text = pubConfig["co_typename"].ToString(); tboxPubTypeid.Text = pubConfig["pub_typeid"].ToString(); tboxPubTypename.Text = pubConfig["pub_typename"].ToString(); tboxPubFilterKeywords.Text = pubConfig["pub_filter_keywords"].ToString(); tboxRandomDateStart.Text = pubConfig["random_date_start"].ToString(); tboxRandomDateStop.Text = pubConfig["random_date_stop"].ToString(); setVarValue(); //将控件中的值同步到对应的变量中 } else { MessageBox.Show(string.Format("数据加载错误:{0}", sResult)); } }
private void initializeForm() { mySqlDB coMyDB = new mySqlDB(_coConnString); string sResult = ""; int counts = 0; string sql; listViewPubArticles.BeginUpdate(); foreach (string item in _ListPubID) { int pubID = int.Parse(item); sql = "select * from pub_config where id='" + item + "'"; List <Dictionary <string, object> > pubConfigRecords = coMyDB.GetRecords(sql, ref sResult, ref counts); if (sResult == mySqlDB.SUCCESS && counts > 0) { _queuePubID.Enqueue(pubID); string pubName = pubConfigRecords[0]["pub_name"].ToString(); string coTypename = pubConfigRecords[0]["co_typename"].ToString(); string pubTypename = pubConfigRecords[0]["pub_typename"].ToString(); string pubNums = pubConfigRecords[0]["pub_nums"].ToString(); string[] subItems = new string[] { "待发布", item, pubName, coTypename, pubTypename, pubNums, "0", "0" }; ListViewItem listItem = new ListViewItem(subItems); listViewPubArticles.Items.Add(listItem); } } listViewPubArticles.EndUpdate(); listViewPubArticles.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); listViewPubArticles.GridLines = true; }
//随机获取一条符合发布条件的文章记录 private Dictionary <string, object> getOneRecord() { List <Dictionary <string, object> > dbResult; mySqlDB myDB = new mySqlDB(_coConnString); string sResult = ""; int counts = 0; string sql = "select aid,litpic,title,source_site,description,content from arc_contents where type_id='" + _coTypeid.ToString() + "' and usedby_pc='no'"; string countSql = "select count(aid) from arc_contents where type_id='" + _coTypeid.ToString() + "' and usedby_pc='no'"; if (_pubFilterKeywords.Length > 0) { sql = sql + " and (title like '%" + _pubFilterKeywords[0] + "%'"; countSql = countSql + " and (title like '%" + _pubFilterKeywords[0] + "%'"; for (int i = 1; i < _pubFilterKeywords.Length; i++) { sql = sql + " or title like '%" + _pubFilterKeywords[i] + "%'"; countSql = countSql + " or title like '%" + _pubFilterKeywords[i] + "%'"; } sql = sql + ")"; countSql = countSql + ")"; } int startPosition = getRandomStartPosition(countSql); if (startPosition != 0) { sql = sql + " order by aid limit " + startPosition.ToString() + ",1"; } else { sql = sql + " order by aid limit 1"; } dbResult = myDB.GetRecords(sql, ref sResult, ref counts); if (sResult == mySqlDB.SUCCESS && counts > 0) { return(dbResult[0]); } else { if (sResult != mySqlDB.SUCCESS) { Exception ex = new Exception(sResult); ex.Data.Add("错误信息", "从指定采集分类中获取未发布文章错误"); ex.Data.Add("采集分类ID", _coTypeid); _pubExceptions.Add(ex); } if (counts == 0) { Exception ex = new Exception(sResult); ex.Data.Add("提示信息", "指定采集分类中已没有可发布的文章"); ex.Data.Add("采集分类ID", _coTypeid); _cancelException = ex; } return(null); } }
private void setPubArticleDescription(object state) { _coConnString = GetCoConnString(); _pubConnString = GetPubConnString(); int finishedArticles = 0; if (_pubConnString != "" && _coConnString != "") { System.Threading.Timer timer = new System.Threading.Timer( //timeCB, //PrintTime, //TimerCallBack委托对象 delegate { this.Invoke((Action) delegate { lblFinishedGetPubArcDescCount.Text = string.Format("{0}", finishedArticles); }); }, //(object state)=>labTime.Text = string.Format("Time is {0}\n", DateTime.Now.ToLongTimeString()), null, //想传入的参数 (null表示没有参数) 0, //在开始之前,等待多长时间(以毫秒为单位) 1000); //每次调用的间隔时间(以毫秒为单位) mySqlDB coMyDB = new mySqlDB(_coConnString); string sResult = ""; int counts = 0; string sql = "select aid,cms_aid,description from arc_contents where description is not null and cms_aid is not null"; List <Dictionary <string, object> > coRecords = coMyDB.GetRecords(sql, ref sResult, ref counts); if (sResult == mySqlDB.SUCCESS && counts > 0) { foreach (Dictionary <string, object> item in coRecords) { string cms_aid = item["cms_aid"].ToString(); string description = item["description"].ToString(); mySqlDB pubMyDB = new mySqlDB(_pubConnString); sql = "update " + _pubTablePrename + "_news set description='" + description + "' where id='" + cms_aid + "'"; counts = pubMyDB.executeDMLSQL(sql, ref sResult); if (counts > 0 && sResult == mySqlDB.SUCCESS) { finishedArticles += 1; } else { tboxArctoolOutput.AppendText(string.Format("错误信息:{0}\n", sResult)); } } } } else { MessageBox.Show("请正确配置发布数据库参数!"); } }
//加载发布分类信息 private void loadPubTypeInfo(string searchCondition = "") { listViewPubTypeinfo.Items.Clear(); mySqlDB myDB = new mySqlDB(_pubConnString); string sResult = ""; int counts = 0; string sql = "select catid,catname,items from " + _pubTablePrename + "_category where parentid <> 0 and modelid=1"; if (searchCondition != "") { sql = sql + " and catname like '%" + searchCondition + "%'"; } List <Dictionary <string, object> > listPubTypeinfo = myDB.GetRecords(sql, ref sResult, ref counts); if (sResult == mySqlDB.SUCCESS && counts > 0) { listViewPubTypeinfo.BeginUpdate(); foreach (Dictionary <string, object> item in listPubTypeinfo) { List <string> subItems = new List <string>(); foreach (KeyValuePair <string, object> kvp in item) { subItems.Add(kvp.Value.ToString()); } ListViewItem listItem = new ListViewItem(subItems.ToArray()); listViewPubTypeinfo.Items.Add(listItem); } listViewPubTypeinfo.EndUpdate(); listViewPubTypeinfo.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); } else { if (counts == 0) { MessageBox.Show(string.Format("未找到搜索的分类!")); } else { MessageBox.Show(string.Format("加载采集分类数据出错!:{0}", sResult)); } } }
//从数据库中加载配置 private void displayConfig() { mySqlDB myDB = new mySqlDB(_connString); string sResult = ""; int counts = 0; string sql = @"select * from co_config where cid = '" + _cid.ToString() + "'"; List <Dictionary <string, object> > coConfigRecords = myDB.GetRecords(sql, ref sResult, ref counts); if (sResult == mySqlDB.SUCCESS) { Dictionary <string, object> coConfig = coConfigRecords[0]; tboxCoName.Text = coConfig["co_name"].ToString(); cboxCoSource_Lang.Text = coConfig["source_lang"].ToString(); cboxCoSource_Site.Text = coConfig["source_site"].ToString(); cboxCoTypeName.Text = coConfig["type_name"].ToString(); if (coConfig["co_offline"].ToString() == "yes") { rbtnCo_Offline_yes.Checked = true; } else { rbtnCo_Offline_no.Checked = true; } tboxCoListPath.Text = coConfig["list_path"].ToString(); tboxCoStartPageNumber.Text = coConfig["start_page_number"].ToString(); tboxCoStopPageNumber.Text = coConfig["stop_page_number"].ToString(); tboxMoreListPages.Text = coConfig["more_list_pages"].ToString(); tboxXpathArcurlNode.Text = coConfig["xpath_arcurl_node"].ToString(); tboxXpathTitleNode.Text = coConfig["xpath_title_node"].ToString(); tboxXpathContentNode.Text = coConfig["xpath_content_node"].ToString(); tboxArcSubpageSymbol.Text = coConfig["arc_subpage_symbol"].ToString(); tboxArcSubpageStartNum.Text = coConfig["arc_subpage_startnum"].ToString(); tboxSubNodeParams.Text = coConfig["sub_node_params"].ToString(); tboxRegexParams.Text = coConfig["regex_params"].ToString(); setVarValue(); //将控件中的值同步到对应的变量中 } else { MessageBox.Show(string.Format("数据加载错误:{0}", sResult)); } }
//查寻符合发布条件的文章总数,根据文章总数随机一个从1到总数的数,作为获取一条记录的起始位置 private int getRandomStartPosition(string sql) { int startPosition = 0; int recordCounts = 0; List <Dictionary <string, object> > dbResult; mySqlDB myDB = new mySqlDB(_coConnString); string sResult = ""; int counts = 0; dbResult = myDB.GetRecords(sql, ref sResult, ref counts); if (sResult == mySqlDB.SUCCESS && counts > 0) { recordCounts = int.Parse(dbResult[0]["count(aid)"].ToString()); if (recordCounts != 0) { Random rnd = new Random(); startPosition = rnd.Next(1, recordCounts); } } return(startPosition); }
//随机获取一条符合发布条件的文章记录 private Dictionary <string, object> getOneRecord() { List <Dictionary <string, object> > dbResult; mySqlDB myDB = new mySqlDB(_coConnString); string sResult = ""; int counts = 0; //查寻符合发布条件的文章记录,满足条件必须包括 is_edited字段为yes, usedby_pc字段为no, cms_typeid字段不能为null, 如果传入参数aid,则查寻指定aid的文章 string sql = "select aid,litpic,title,type_id,cms_typeid,source_site,description,keywords,content from arc_contents where is_edited='yes' and usedby_pc='no' and cms_typeid<>'null'"; if (_aid != 0) { sql = sql + " and aid='" + _aid.ToString() + "'"; } else { sql = sql + " order by aid limit 1"; } dbResult = myDB.GetRecords(sql, ref sResult, ref counts); if (sResult == mySqlDB.SUCCESS && counts > 0) { return(dbResult[0]); } else { if (sResult != mySqlDB.SUCCESS) { Exception ex = new Exception(sResult); ex.Data.Add("错误信息", "获取未发布文章错误"); _pubExceptions.Add(ex); } if (counts == 0) { Exception ex = new Exception(sResult); ex.Data.Add("提示信息", "没有可发布的文章"); _cancelException = ex; } return(null); } }
private void getCoArticleDescription(object state) { _coConnString = GetCoConnString(); int descriptionLength = 120; int finishedArticles = 0; if (int.TryParse(tboxCoArcDescLength.Text, out descriptionLength)) { descriptionLength = int.Parse(tboxCoArcDescLength.Text); } else { MessageBox.Show("文章概要长度值不是整数,使用默认长度120!"); } if (_coConnString != "") { System.Threading.Timer timer = new System.Threading.Timer( //timeCB, //PrintTime, //TimerCallBack委托对象 delegate { this.Invoke((Action) delegate { lblFinishedGetCoArcDescCounts.Text = string.Format("{0}", finishedArticles); }); }, //(object state)=>labTime.Text = string.Format("Time is {0}\n", DateTime.Now.ToLongTimeString()), null, //想传入的参数 (null表示没有参数) 0, //在开始之前,等待多长时间(以毫秒为单位) 1000); //每次调用的间隔时间(以毫秒为单位) mySqlDB coMyDB = new mySqlDB(_coConnString); string sResult = ""; int counts = 0; string sql = "select aid,title,content from arc_contents where description is null limit 1"; List <Dictionary <string, object> > articleRecord = new List <Dictionary <string, object> >(); articleRecord = coMyDB.GetRecords(sql, ref sResult, ref counts); while (sResult == mySqlDB.SUCCESS && counts > 0) { string aid = articleRecord[0]["aid"].ToString(); string title = articleRecord[0]["title"].ToString(); string arcContent = articleRecord[0]["content"].ToString(); HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); try { doc.LoadHtml(arcContent); string arcContentPiece = doc.DocumentNode.InnerText; arcContentPiece = arcContentPiece.Replace("\r\n\t", ""); arcContentPiece = arcContentPiece.Replace("\r\n", ""); arcContentPiece = arcContentPiece.Replace("\r", ""); arcContentPiece = arcContentPiece.Replace("\n", ""); arcContentPiece = arcContentPiece.Replace("\t", ""); arcContentPiece = arcContentPiece.Replace(" ", ""); arcContentPiece = arcContentPiece.Replace("amp;", ""); arcContentPiece = arcContentPiece.Replace(" ", ""); if (arcContentPiece.Length > 200) { arcContentPiece = arcContentPiece.Substring(0, 200); } string description = ArcTool.GetDescription(arcContentPiece, descriptionLength); string updateSql = "update arc_contents set description='" + description + "' where aid='" + aid + "'"; counts = coMyDB.executeDMLSQL(updateSql, ref sResult); if (sResult == mySqlDB.SUCCESS && counts > 0) { finishedArticles += 1; } else { tboxArctoolOutput.AppendText(string.Format("错误信息:{0}\n", sResult)); } } catch (Exception ex) { tboxArctoolOutput.AppendText(string.Format("错误信息:{0}: {1} : {2} \n", aid, title, ex.Message)); } //再次从数据里获取一篇文章 articleRecord = coMyDB.GetRecords(sql, ref sResult, ref counts); } } else { MessageBox.Show("请正确配置采集数据库参数!"); } }
//加载采集规则方法 private void loadPubConfig() { _coConnString = GetCoConnString(); _pubConnString = GetPubConnString(); if (_coConnString != "" && _pubConnString != "") { listViewPublish.Items.Clear(); mySqlDB myDB = new mySqlDB(_coConnString); string sResult = ""; int counts = 0; string filter = getPubFilter(); string sql = @"select id,pub_name,co_typename,arc_type.unused_nums,pub_typename,pub_nums,published_nums,pub_add_date,pub_export_date from pub_config left join arc_type on pub_config.co_typeid=arc_type.tid"; if (filter != "") { sql += filter; } List <Dictionary <string, object> > pubConfigRecords = myDB.GetRecords(sql, ref sResult, ref counts); if (sResult == mySqlDB.SUCCESS) { listViewPublish.GridLines = true; listViewPublish.BeginUpdate(); foreach (Dictionary <string, object> item in pubConfigRecords) { List <string> subItems = new List <string>(); foreach (KeyValuePair <string, object> kvp in item) { if (kvp.Key == "pub_add_date" || kvp.Key == "pub_export_date") { string fullDate = kvp.Value.ToString(); try //尝试将完整时间格式转换成短日期格式 { if (fullDate == "") { subItems.Add(fullDate); } else { DateTime dt = DateTime.Parse(fullDate); string shortDate = dt.ToShortDateString(); subItems.Add(shortDate); } } catch (Exception) //如果转换失败,则继续用完整日期格式 { subItems.Add(fullDate); } } else { if (kvp.Key == "unused_nums") { string unUsedNums = kvp.Value.ToString(); if (unUsedNums == "") { unUsedNums = "0"; } subItems.Add(unUsedNums); } else { subItems.Add(kvp.Value.ToString()); } } } ListViewItem listItem = new ListViewItem(subItems.ToArray()); listViewPublish.Items.Add(listItem); } listViewPublish.EndUpdate(); listViewPublish.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); } else { MessageBox.Show(string.Format("加载数据出错!:{0}", sResult)); } } else { MessageBox.Show("请正确填写采集数据库和发布数据库配置信息!"); } }
//加载采集规则 private void loadCoConfig() { _coConnString = GetCoConnString(); if (_coConnString != "") { listViewCollect.Items.Clear(); mySqlDB myDB = new mySqlDB(_coConnString); string sResult = ""; int counts = 0; string filter = getCoFilter(); string sql = @"select cid,co_name,type_name,source_lang,source_site,up_time,co_time,co_nums from co_config"; if (filter != "") { sql += filter; } List <Dictionary <string, object> > coConfigRecords = myDB.GetRecords(sql, ref sResult, ref counts); if (sResult == mySqlDB.SUCCESS) { listViewCollect.GridLines = true; listViewCollect.BeginUpdate(); foreach (Dictionary <string, object> item in coConfigRecords) { List <string> subItems = new List <string>(); foreach (KeyValuePair <string, object> kvp in item) { if (kvp.Key == "up_time" || kvp.Key == "co_time") { string fullDate = kvp.Value.ToString(); try //尝试将完整时间格式转换成短日期格式 { if (fullDate == "") { subItems.Add(fullDate); } else { DateTime dt = DateTime.Parse(fullDate); string shortDate = dt.ToShortDateString(); subItems.Add(shortDate); } } catch (Exception) //如果转换失败,则继续用完整日期格式 { subItems.Add(fullDate); } } else { subItems.Add(kvp.Value.ToString()); } } ListViewItem listItem = new ListViewItem(subItems.ToArray()); listViewCollect.Items.Add(listItem); } listViewCollect.EndUpdate(); listViewCollect.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); } else { MessageBox.Show(string.Format("加载数据出错!:{0}", sResult)); } } }
//生成文章点击数数据 private void createHitsRecords(object state) { _pubConnString = GetPubConnString(); int finishedArticles = 0; if (_pubConnString != "") { System.Threading.Timer timer = new System.Threading.Timer( //timeCB, //PrintTime, //TimerCallBack委托对象 delegate { this.Invoke((Action) delegate { lblFinishedCreateHitsRecordsCount.Text = string.Format("{0}", finishedArticles); }); }, //(object state)=>labTime.Text = string.Format("Time is {0}\n", DateTime.Now.ToLongTimeString()), null, //想传入的参数 (null表示没有参数) 0, //在开始之前,等待多长时间(以毫秒为单位) 1000); //每次调用的间隔时间(以毫秒为单位) } mySqlDB pubMydb = new mySqlDB(_pubConnString); string sResult = ""; int counts = 0; string sql = "select count(id) from " + _pubTablePrename + "_news"; List <Dictionary <string, object> > dbResult = new List <Dictionary <string, object> >(); dbResult = pubMydb.GetRecords(sql, ref sResult, ref counts); if (sResult == mySqlDB.SUCCESS && counts > 0) { int articleCounts = int.Parse(dbResult[0]["count(id)"].ToString()); tboxArctoolOutput.AppendText(string.Format("文章总数:{0}\n", articleCounts)); int startPosition = 0; int onceNums = 1000; if (articleCounts > 0) { while (startPosition < articleCounts) { sql = "select id,catid from " + _pubTablePrename + "_news limit " + startPosition.ToString() + "," + onceNums.ToString(); dbResult = pubMydb.GetRecords(sql, ref sResult, ref counts); if (sResult == mySqlDB.SUCCESS && counts > 0) { foreach (Dictionary <string, object> item in dbResult) { string id = item["id"].ToString(); string catid = item["catid"].ToString(); string hitsid = "c-1-" + id.ToString(); sql = "INSERT IGNORE INTO " + _pubTablePrename + "_hits(hitsid,catid) Values('" + hitsid + "','" + catid + "')"; counts = pubMydb.executeDMLSQL(sql, ref sResult); if (sResult == mySqlDB.SUCCESS && counts > 0) { finishedArticles += 1; } else { tboxArctoolOutput.AppendText(string.Format("插入hits表数据出错或记录已存在!sql语句:{0} 错误信息:{1}\n", sql, sResult)); } } startPosition += onceNums; } else { tboxArctoolOutput.AppendText("CMS数据库获取文章ID和分类ID出错!终止\n"); break; } } } } } }
private void displayArticles(int typeID, string searchArcTitle = "", int displayCount = 0, bool onlyUnEdited = false) { if (typeID != 0) { mySqlDB myDB = new mySqlDB(_coConnString); string sResult = ""; int counts = 0; string sql = "select aid,pic_count,is_edited,title from arc_contents where usedby_pc='no' and type_id='" + typeID.ToString() + "'"; sql = sql + " and is_display='yes'"; if (onlyUnEdited) { sql = sql + " and is_edited='no'"; } if (searchArcTitle != "") { sql = sql + " and title like '%" + searchArcTitle + "%'"; } //sql = sql + " order by aid DESC"; if (displayCount != 0) { sql = sql + " limit " + displayCount.ToString(); } else { sql = sql + " limit 100"; } List <Dictionary <string, object> > listArticles = myDB.GetRecords(sql, ref sResult, ref counts); listViewArticles.Items.Clear(); if (sResult == mySqlDB.SUCCESS && counts > 0) { listViewArticles.BeginUpdate(); foreach (Dictionary <string, object> item in listArticles) { List <string> subItems = new List <string>(); foreach (KeyValuePair <string, object> kvp in item) { subItems.Add(kvp.Value.ToString()); } ListViewItem listItem = new ListViewItem(subItems.ToArray()); listViewArticles.Items.Add(listItem); } listViewArticles.EndUpdate(); listViewArticles.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); } else { if (counts == 0) { //MessageBox.Show("当前分类没有可发布文章!"); } else { MessageBox.Show("获取文章出错!"); } } } else { MessageBox.Show("请选择文章分类!"); } }
private void startOneTask(object state) { int pubID = getOnePubID(); if (pubID != -1) { mySqlDB coMyDB = new mySqlDB(_coConnString); string sResult = ""; int counts = 0; string sql = "select * from pub_config where id='" + pubID.ToString() + "'"; List <Dictionary <string, object> > pubConfigRecords = coMyDB.GetRecords(sql, ref sResult, ref counts); if (sResult == mySqlDB.SUCCESS && counts > 0) { Dictionary <string, object> dicConfig = pubConfigRecords[0]; Dictionary <string, string> checkFields = new Dictionary <string, string>(); checkFields.Add("id", dicConfig["id"].ToString()); checkFields.Add("pub_name", dicConfig["pub_name"].ToString()); checkFields.Add("co_typeid", dicConfig["co_typeid"].ToString()); checkFields.Add("co_typename", dicConfig["co_typename"].ToString()); checkFields.Add("pub_typeid", dicConfig["pub_typeid"].ToString()); checkFields.Add("pub_typename", dicConfig["pub_typename"].ToString()); checkFields.Add("pub_nums", dicConfig["pub_nums"].ToString()); checkFields.Add("random_date_start", dicConfig["random_date_start"].ToString()); checkFields.Add("random_date_stop", dicConfig["random_date_stop"].ToString()); if (!validatePubConfig(checkFields)) { tboxErrorOutput.AppendText(string.Format("采集规则: (ID:{0}) 配置检查错误,请重新编辑采集规则项,确认必填项数据都已正确填写! \n", pubID)); } else { int coTypeid = int.Parse(dicConfig["co_typeid"].ToString()); int pubTypeid = int.Parse(dicConfig["pub_typeid"].ToString()); int pubNums = int.Parse(dicConfig["pub_nums"].ToString()); string randomDateStart = dicConfig["random_date_start"].ToString(); string randomDateStop = dicConfig["random_date_stop"].ToString(); string[] pubFilterKeywords = new string[0]; if (dicConfig["pub_filter_keywords"].ToString() != "") { pubFilterKeywords = dicConfig["pub_filter_keywords"].ToString().Split('|'); } ArticlePublish articlePublish = new ArticlePublish(pubID, _coConnString, _pubConnString, _pubTablePrename, coTypeid, pubTypeid, pubNums, pubFilterKeywords, randomDateStart, randomDateStop); CancellationTokenSource cancelTokenSource = new CancellationTokenSource(); articlePublish.CancelTokenSource = cancelTokenSource; //articlePublish.ProcessPublishArticles(); //创建发布任务的监控时钟,并且开始记时 Stopwatch sw = new Stopwatch(); sw.Start(); //通过委托代理异步执行发布任务 PublishProcess publishProcesArticles = new PublishProcess(ProcessPublishArticles); publishProcesArticles.BeginInvoke(articlePublish, ProcessPublishArticlesComplete, null); //创建新的Dictionary集合,其中包括采集对象,包括用来监控耗时的Stopwatch对象 Dictionary <string, object> oneCollect = new Dictionary <string, object>(); oneCollect.Add("publish", articlePublish); oneCollect.Add("watch", sw); //将当前采集对象添加到全局用来监控采集进程的采集对象集合中。 bool addResult = false; do { addResult = _articlePubCollections.TryAdd(pubID, oneCollect); } while (!addResult); } } else { tboxErrorOutput.AppendText(string.Format("发布规则(ID:{0}) 读取数据库采集配置错误!:{1} \n", pubID, sResult)); } } }