• ConcurrentDictionary 用法


    using Iot.Model.SklDtos;
    using WindowsTcpip.Server;
    using System;
    using System.Collections.Concurrent;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Diagnostics;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Iot.Dal.Base;
    using Iot.Common;
    using Iot.Model;
    using Newtonsoft.Json;
    using Iot.Factory;
    using Aliyun.MNS.Model;
    using Aliyun.MNS;
    using System.Threading;
    using Iot.Model.BatteryTcpip;
    using Iot.Model.Pagination;
    using Iot.Dal.WA_Device;
    
    namespace SktServer
    {
        class Program
        {
            public static ConcurrentDictionary<int, BatteryOtaModel> OtaList = new ConcurrentDictionary<int, BatteryOtaModel>();
            static void Main(string[] args)
            {
                var otaef = OtaList.Where(A => A.Key == 1).FirstOrDefault();
                if (otaef.Value != null && !string.IsNullOrEmpty(otaef.Value.BatterySn))
                {
                   
                }
                else
                {
                    OtaList.TryAdd(1, new BatteryOtaModel() { BatterySn = "123", OtaNumber = 1 });
                  
                }
                otaef = OtaList.Where(A => A.Key == 1).FirstOrDefault();
                if (otaef.Value != null && !string.IsNullOrEmpty(otaef.Value.BatterySn))
                {
                    otaef.Value.BatterySn = "333";
                    otaef.Value.OtaNumber = 2;
                }
                if (otaef.Value != null && !string.IsNullOrEmpty(otaef.Value.BatterySn))
                {
                    otaef.Value.BatterySn = "444";
                    otaef.Value.OtaNumber = 3;
                }
                var ef = OtaList.Where(A => A.Key == 1).FirstOrDefault();
                BatteryOtaModel mol = new BatteryOtaModel();
                OtaList.TryRemove(1, out mol);
                
                Console.Read();
            }
    
            public class BatteryOtaModel
            {
                public string BatterySn { get; set; }
                public long OtaNumber { get; set; }
            }
        }
    }
  • 相关阅读:
    geoServer的安装
    类设计原则
    零散知识点
    JavaScript setTimeOut()方法的一些疑点自己记录
    贴吧表情雨
    Laravel中tosql()是如何返回sql
    关于new static 与 new self的区别(后续有新发现,会继续更新)
    Lumen、Laravel开发问题记录
    文件实时对比,将数据组装入库(SQLITE)
    PHPSTUDY下升级mysql后无法启动
  • 原文地址:https://www.cnblogs.com/chenwolong/p/14217619.html
Copyright © 2020-2023  润新知