C# 队列、锁、异步

//创建队列
private static ConcurrentQueue<ad_playrecord_count> _Concurrenplayrecord_count { get; set; }
//实现队列
_Concurrenplayrecord_count = new ConcurrentQueue<ad_playrecord_count>();
//进队列 
ad_playrecord_count prcModel = new ad_playrecord_count();
prcModel.XX="2222"; _Concurrenplayrecord_count.Enqueue(prcModel);
//出队列 while (_Concurrenplayrecord_count.Count > 0) { ad_playrecord_count prcModel_queue = null; _Concurrenplayrecord_count.TryDequeue(out prcModel_queue); context.ad_playrecord_count.Add(prcModel_queue); context.SaveChanges(); }
 //建立锁,用来传文件
private static object o = new object();
lock (o)
{
      file.SaveAs(FilePath + FileName + fileExt);
}                     

 Task t1 = Task.Factory.StartNew(() => //创建t1
{

});
 Task t2 = Task.Factory.StartNew(() => //创建t2
{

});
Task.WaitAll(t1, t2);//等待t1,t2执行完毕

 

posted @ 2018-12-14 15:04  ly丶乐  阅读(1258)  评论(0编辑  收藏  举报