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執行完畢
 
        

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM