您的位置:首页 > 其它

消息队列使用,异步执行,加快速度

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)

{

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: