消息队列使用,异步执行,加快速度
2015-11-20 09:55
369 查看
//定义队列
private readonly Queue<TrainLandingPageInfo> documentQueue = new Queue<TrainLandingPageInfo>();
public void AddDocument(TrainLandingPageInfo model)
{
lock (this)
{
documentQueue.Enqueue(model);
//如果线程未启动,则启动线程,否则只要加入到队列中便可以了。
if (threadWatch==null || !threadWatch.IsAlive)
{
//创建线程
threadWatch = new Thread(AddLoadpage);
//启动线程
threadWatch.Start();
}
}
}
//处理队列数据
private void AddLoadpage()
{
while (documentQueue.Count > 0)
{
TrainLandingPageInfo client = GetDocument();
try
{
int pid = TrainLanPageDAL.AddFcate(client.fidname, client.SiteID, 0);
client.CatID = TrainLanPageDAL.AddFcate(client.catname, client.SiteID, pid);
if (client.CatID > 0)
TrainLanPageDAL.AddLoadpage(client);
}
catch (Exception ex)
{
}
}
}
private readonly Queue<TrainLandingPageInfo> documentQueue = new Queue<TrainLandingPageInfo>();
public void AddDocument(TrainLandingPageInfo model)
{
lock (this)
{
documentQueue.Enqueue(model);
//如果线程未启动,则启动线程,否则只要加入到队列中便可以了。
if (threadWatch==null || !threadWatch.IsAlive)
{
//创建线程
threadWatch = new Thread(AddLoadpage);
//启动线程
threadWatch.Start();
}
}
}
//处理队列数据
private void AddLoadpage()
{
while (documentQueue.Count > 0)
{
TrainLandingPageInfo client = GetDocument();
try
{
int pid = TrainLanPageDAL.AddFcate(client.fidname, client.SiteID, 0);
client.CatID = TrainLanPageDAL.AddFcate(client.catname, client.SiteID, pid);
if (client.CatID > 0)
TrainLanPageDAL.AddLoadpage(client);
}
catch (Exception ex)
{
}
}
}
相关文章推荐
- Lombok精简Java代码及安装使用
- javascript中数组方法小计
- 数据库某些要注意的问题(转的,侵权删除)
- android-eclips中logcat不显示信息的问题解决
- WPF自定义控件与样式(5)-Calendar/DatePicker日期控件自定义样式及扩展(转)
- jsp spring mvc 上传时HTTP Status 405 - Request method 'GET' not supported是什么原因
- MySQL5.6新特性之GTID、多线程复制 - 不知为何
- SecureCRT 快捷键
- 每天一点python —— 迭代器与生成器
- KMeans简单实现
- JAVA 播放声音
- 【Leetcode】Reverse Nodes in k-Group
- 「大概可能也许是」目前最好的 JavaScript 异步方案 async/await
- [OpenCV] VS2010中OpenCV2.X配置Debug和Release同时正常使用
- Scala 通过 JNI 连接 C++程序
- TeamCity 持续集成-持续学习
- Android CursorAdapter的使用
- iPhone开发之全局变量的使用
- cgi ISAP sapi等
- 66、fastJson 解析json数据时,如果key值不同怎么处理?