//定义队列
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)
{
}
}
}