当前位置: 首页>>代码示例>>C#>>正文


C# Threading.ReaderWriterLockSlim类代码示例

本文整理汇总了C#中System.Threading.ReaderWriterLockSlim的典型用法代码示例。如果您正苦于以下问题:C# ReaderWriterLockSlim类的具体用法?C# ReaderWriterLockSlim怎么用?C# ReaderWriterLockSlim使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ReaderWriterLockSlim类属于System.Threading命名空间,在下文中一共展示了ReaderWriterLockSlim类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BlockLock

        /// <summary>
        /// Acquires a read lock on both the block and the block collection.
        /// </summary>
        /// <param name="collectionLock">The lock on the block collection.</param>
        /// <param name="blockLock">The lock object used to acquire the lock.</param>
        /// <param name="requestLock"></param>
        public BlockLock(
			IDisposable collectionLock,
			ReaderWriterLockSlim accessLock,
			RequestLock requestLock)
        {
            // Keep track of the collection lock so we can release it.
            this.collectionLock = collectionLock;

            // Acquire the lock based on the requested type.
            switch (requestLock)
            {
                case RequestLock.Read:
                    blockLock = new NestableReadLock(accessLock);
                    break;

                case RequestLock.UpgradableRead:
                    blockLock = new NestableUpgradableReadLock(accessLock);
                    break;

                case RequestLock.Write:
                    blockLock = new NestableWriteLock(accessLock);
                    break;

                default:
                    throw new InvalidOperationException(
                        "Could not acquire lock with unknown type: " + requestLock);
            }
        }
开发者ID:dmoonfire,项目名称:author-intrusion-cil,代码行数:34,代码来源:BlockLock.cs

示例2: Dispose_Errors

        public void Dispose_Errors()
        {
            var v = new ReaderWriterLockSlim();
            v.Dispose();

            try
            {
                v.EnterUpgradeableReadLock();
                Assert.Fail("1");
            }
            catch (ObjectDisposedException)
            {
            }

            try
            {
                v.EnterReadLock();
                Assert.Fail("2");
            }
            catch (ObjectDisposedException)
            {
            }

            try
            {
                v.EnterWriteLock();
                Assert.Fail("3");
            }
            catch (ObjectDisposedException)
            {
            }
        }
开发者ID:mesheets,项目名称:Theraot-CF,代码行数:32,代码来源:ReaderWriterLockSlimTest.cs

示例3: Topic

 public Topic(uint storeSize, TimeSpan lifespan)
 {
     _lifespan = lifespan;
     Subscriptions = new List<ISubscription>();
     Store = new MessageStore<Message>(storeSize);
     SubscriptionLock = new ReaderWriterLockSlim();
 }
开发者ID:avanderhoorn,项目名称:SimpleSockets,代码行数:7,代码来源:Topic.cs

示例4: Region

        public Region(int id)
        {
            _creaturesRWLS = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
            _propsRWLS = new ReaderWriterLockSlim();
            _itemsRWLS = new ReaderWriterLockSlim();

            this.Id = id;

            _creatures = new Dictionary<long, Creature>();
            _props = new Dictionary<long, Prop>();
            _items = new Dictionary<long, Item>();

            _clients = new HashSet<ChannelClient>();

            _regionData = AuraData.RegionInfoDb.Find(this.Id);
            if (_regionData == null)
            {
                Log.Warning("Region: No data found for '{0}'.", this.Id);
                return;
            }

            this.Collissions = new RegionCollision(_regionData.X1, _regionData.Y1, _regionData.X2, _regionData.Y2);
            this.Collissions.Init(_regionData);

            this.LoadClientProps();
        }
开发者ID:pie3467,项目名称:aura,代码行数:26,代码来源:Region.cs

示例5: DefaultNodeLocator

		public DefaultNodeLocator()
		{
			this.servers = new Dictionary<uint, IMemcachedNode>(new UIntEqualityComparer());
			this.deadServers = new Dictionary<IMemcachedNode, bool>();
			this.allServers = new List<IMemcachedNode>();
			this.serverAccessLock = new ReaderWriterLockSlim();
		}
开发者ID:javithalion,项目名称:NCache,代码行数:7,代码来源:DefaultNodeLocator.cs

示例6: Rider

 public Rider()
 {
     _outputDatum = new InterfaceDatum();
     _datumLock = new ReaderWriterLockSlim();
     _IsSent = true; // This will prevent any send until new data are available
     _rnd = new Random();        // For test data
 }
开发者ID:Cycli,项目名称:Cycli,代码行数:7,代码来源:Rider.cs

示例7: MorphologicalFilteringOptionsViewModel

        public MorphologicalFilteringOptionsViewModel()
        {
            StackSync = new ReaderWriterLockSlim();

            if (Execute.InDesignMode)
                LoadDesignTimeData();
        }
开发者ID:vladimirdjurdjevic,项目名称:soft,代码行数:7,代码来源:MorphologicalFilteringOptionsViewModel.cs

示例8: NntpParser

        public NntpParser(NzbConnection connection)
        {
            ArgumentChecker.ThrowIfNull("connection", connection);

            _connection = connection;
            _synchronizationObject = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
        }
开发者ID:Rawrpwnzl,项目名称:Binary-Newsgroups-Library,代码行数:7,代码来源:NntpParser.cs

示例9: GraphicManager

        protected int timerPerion; // частота отрисовки графиков в активном режиме

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Инициализирует новый экземпляр класса
        /// </summary>
        /// <param name="GPanel">Панель которую будет обслуживать манеджер</param>
        public GraphicManager(Panel GPanel)
        {
            mutex = new Mutex();
            slim = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);

            mode = DrawMode.Default;

            if (GPanel != null)
            {
                panel = GPanel;
                //panel.StartTime = DateTime.Now;

                panel.OnResize += new EventHandler(Sheet_Resize);

                panel.Sheet.onOrientationChange += new EventHandler(Sheet_onOrientationChange);
                panel.Sheet.onIntervalInCellChange += new EventHandler(Sheet_onIntervalInCellChange);

                timerPerion = 500;
                timer = new Timer(TimerCallback, null, Timeout.Infinite, timerPerion);
            }
            else
            {
                throw new ArgumentNullException();
            }
        }
开发者ID:slawer,项目名称:skc,代码行数:35,代码来源:GraphicManager.cs

示例10: Repository

        protected List<Place> places = null; // место в репозитарии

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Инициализирует новый экземпляр класса
        /// </summary>
        public Repository()
        {
            mutex = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);

            places = new List<Place>();
            packets = new List<Packet>();
        }
开发者ID:slawer,项目名称:devicemanager,代码行数:16,代码来源:Repository.cs

示例11: ServiceHost

		public ServiceHost(int servicePort)
		{
			pools = new List<SocketPool>();
			poolsLock = new ReaderWriterLockSlim();
			container = new ServiceContainer();
			this.servicePort = servicePort;
		}
开发者ID:epdumitru,项目名称:mysqlib,代码行数:7,代码来源:ServiceHost.cs

示例12: RideProcessor

        public RideProcessor(string userId)
        {
            _outputLock = new ReaderWriterLockSlim();
            UserId = userId;
            // load the turbo
            _spotData = new Spot();
            _lastSpotData = null;

            // Set-up the lease

            LeaseId = GenerateLease(12);

            // Set the initial timeout
            LastUpdateTimestamp = DateTime.UtcNow;

            _messageQueue = new Queue<InterfaceDatum>(QUEUE_CAPACITY);
            _queueLock = new ReaderWriterLockSlim();
            _zeroingTimer = new Timer(CheckZeroing, null, 1000, 4000);

            _Rider = Rider.LoadAny(userId);

            // will load either a real or virtual rider
            if (_Rider != null)
            {
                _Turbo = TurboTrainer.Load(UserId, _Rider.CurrentTurbo, _Rider.TurboIsCalibrated);
            }
        }
开发者ID:Cycli,项目名称:Cycli,代码行数:27,代码来源:RideProcessor.cs

示例13: SafeReaderWriterLock

 public SafeReaderWriterLock()
 {
     this.locker = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion);
     this.upgradableReaderLock = new SafeUpgradeReaderLock(this.locker);
     this.readerLock = new SafeReaderLock(this.locker);
     this.writerLock = new SafeWriterLock(this.locker);
 }
开发者ID:SalarTam,项目名称:CodeRich,代码行数:7,代码来源:SafeReaderWriterLock.cs

示例14: DbDiskCache

 public DbDiskCache(IFileWrapper fileWrapper, IRRConfiguration configuration, IUriBuilder uriBuilder) : base(fileWrapper, configuration, uriBuilder, null)
 {
     RRTracer.Trace("Creating db disk cache");
     const int interval = 1000*60*5;
     timer = new Timer(PurgeOldFiles, null, 0, interval);
     _cacheLock = new ReaderWriterLockSlim();
 }
开发者ID:ybhatti,项目名称:RequestReduce,代码行数:7,代码来源:DbDiskCache.cs

示例15: PacketReceiver

        internal PacketReceiver(string LocalAddress) : base (LocalAddress)
        {
            packetReceiver = new Queue();
            tokenSource = new CancellationTokenSource();
            readerWriterLock = new ReaderWriterLockSlim();

            tokenSource.Token.Register(() => { 
                // Clear on cancel
                packetReceiver.Clear(); 
            });


            var thReceiveQueue = Task.Factory.StartNew(() => {
                while (tokenSource.Token.IsCancellationRequested == false)
                {
                    readerWriterLock.EnterUpgradeableReadLock();
                    if (packetReceiver.Count > 0)
                    {
                        readerWriterLock.EnterWriteLock();

                        byte[] data = (byte[])packetReceiver.Dequeue();

                        readerWriterLock.ExitWriteLock();

                        if (OnNewPacketReceived != null)
                            OnNewPacketReceived(this, new NewPacketEventArgs(data));
                    }

                    readerWriterLock.ExitUpgradeableReadLock();
                }
            });

        }
开发者ID:jasper22,项目名称:UbuntuUsbMonitor,代码行数:33,代码来源:PacketReceiver.cs


注:本文中的System.Threading.ReaderWriterLockSlim类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。