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


C# Threading.ReaderWriterLock类代码示例

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


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

示例1: LockOnReaderWriterLock

        private static void LockOnReaderWriterLock()
        {
            Console.WriteLine("About to lock on the ReaderWriterLock. Debug after seeing \"Signaled to acquire the reader lock.\"");
            ReaderWriterLock rwLock = new ReaderWriterLock();

            ManualResetEvent rEvent = new ManualResetEvent(false);
            ManualResetEvent pEvent = new ManualResetEvent(false);

            ThreadPool.QueueUserWorkItem((object state) =>
            {
                rwLock.AcquireWriterLock(-1);
                Console.WriteLine("Writer lock acquired!");
                rEvent.Set();
                pEvent.WaitOne();
            });

            rEvent.WaitOne();

            Console.WriteLine("Signaled to acquire the reader lock.");

            rwLock.AcquireReaderLock(-1);

            Console.WriteLine("Reader lock acquired");

            pEvent.Set();

            Console.WriteLine("About to end the program. Press any key to exit.");
            Console.ReadKey();
        }
开发者ID:alienwaredream,项目名称:toolsdotnet,代码行数:29,代码来源:Program.cs

示例2: getOneCell

        public static string getOneCell()
        {
            string encodedOrder=null;
             readSem.WaitOne();// wait until buffer cell is not empty then only read
            ReaderWriterLock rw=new ReaderWriterLock();
            rw.AcquireWriterLock(Timeout.Infinite);
            try{
            //reading from buffer --- ciruclar queue

            if (front_read == bufferSize - 1)
                 front_read = 0;
            else
                 {

                     front_read = front_read + 1;
                  }
               encodedOrder = buffer[front_read];
               buffer[front_read] = string.Empty;
               String[] arr=encodedOrder.Split('#');
               Console.WriteLine("  chicken farm got an order from {0} of {1} chicken",arr[0],arr[2]);
            }
            catch (Exception e){ Console.WriteLine(""); }
            finally
            {
            rw.ReleaseWriterLock();
            writeSem.Release();

            }

            return encodedOrder;
        }
开发者ID:jvutukur,项目名称:DistributedSoftwareDevelopmentProject,代码行数:31,代码来源:MultiBufferCell.cs

示例3: RoleStore

        public RoleStore()
        {
            _loaded = false;
            _cache = new List<Role>();

            _lock = new ReaderWriterLock();
        }
开发者ID:anxkha,项目名称:DRM,代码行数:7,代码来源:RoleStore.cs

示例4: DisposableLockGrabber

        /// <summary>
        /// Initializes a new instance of the <see cref="DisposableLockGrabber"/> class.
        /// </summary>
        /// <param name="rwlock">The rwlock.</param>
        /// <param name="type">The type.</param>
        /// <param name="timeoutMilliseconds">The timeout milliseconds.</param>
        public DisposableLockGrabber(ReaderWriterLock rwlock, ReaderWriterLockSynchronizeType type, int timeoutMilliseconds)
        {
            m_rwlock = rwlock;
            m_type = type;

            DoLock(timeoutMilliseconds);
        }
开发者ID:Yitzchok,项目名称:PublicDomain,代码行数:13,代码来源:DisposableLockGrabber.cs

示例5: RaidInstanceStore

        public RaidInstanceStore()
        {
            _loaded = false;
            _cache = new List<RaidInstance>();

            _lock = new ReaderWriterLock();
        }
开发者ID:anxkha,项目名称:DRM,代码行数:7,代码来源:RaidInstanceStore.cs

示例6: ExecuteJob

 /// <summary>
 /// Executes a job on demand, rather than waiting for its regularly scheduled time.
 /// </summary>
 /// <param name="job">The job to be executed.</param>
 public static void ExecuteJob(JobBase job)
 {
     ReaderWriterLock rwLock = new ReaderWriterLock();
     try
     {
         rwLock.AcquireReaderLock(Timeout.Infinite);
         if (job.Executing == false)
         {
             LockCookie lockCookie = rwLock.UpgradeToWriterLock(Timeout.Infinite);
             try
             {
                 if (job.Executing == false)
                 {
                     job.Executing = true;
                     QueueJob(job);
                 }
             }
             finally
             {
                 rwLock.DowngradeFromWriterLock(ref lockCookie);
             }
         }
     }
     finally
     {
         rwLock.ReleaseReaderLock();
     }
 }
开发者ID:SolidSnake74,项目名称:SharpCore,代码行数:32,代码来源:Scheduler.cs

示例7: ReaderLock

        public ReaderLock(ReaderWriterLock rwLock)
        {
            if (null == rwLock) throw new Exception("Don't pass a null ReaderWriterLock object!");

            _lock = rwLock;
            _lock.AcquireReaderLock(Timeout.Infinite);
        }
开发者ID:anxkha,项目名称:DRM,代码行数:7,代码来源:ReaderLock.cs

示例8: Init

        public static bool Init()
        {
            try
            {
                //_RateInfo = new ExperienceRateInfo();
                //_RateInfo.Rate = 1;
                m_lock = new System.Threading.ReaderWriterLock();

                using (ServiceBussiness db = new ServiceBussiness())
                {
                    _RateInfo = db.GetExperienceRate(WorldMgr.ServerID);
                }

                if (_RateInfo == null)
                {
                    _RateInfo = new ExperienceRateInfo();
                    _RateInfo.Rate = -1;
                }

                return true;
            }
            catch (Exception e)
            {
                if (log.IsErrorEnabled)
                    log.Error("ExperienceRateMgr", e);
                return false;
            }

        }
开发者ID:geniushuai,项目名称:DDTank-3.0,代码行数:29,代码来源:ExperienceRateMgr.cs

示例9: SpecializationStore

        public SpecializationStore()
        {
            _loaded = false;
            _cache = new List<Specialization>();;

            _lock = new ReaderWriterLock();
        }
开发者ID:anxkha,项目名称:DRM,代码行数:7,代码来源:SpecializationStore.cs

示例10: ExpansionStore

        public ExpansionStore()
        {
            _loaded = false;
            _cache = null;

            _lock = new ReaderWriterLock();
        }
开发者ID:anxkha,项目名称:DRM,代码行数:7,代码来源:ExpansionStore.cs

示例11: InitializeConfiguration

		public override void InitializeConfiguration()
		{
            _Entities = new IdentityMap();
            _Scalars = new Dictionary<string,object>();
            _Loads = new Hashtable();
            _RWL = new ReaderWriterLock();
		}
开发者ID:npenin,项目名称:uss,代码行数:7,代码来源:CacheProvider.cs

示例12: HttpApplicationState

		internal HttpApplicationState ()
		{
			// do not use the public (empty) ctor as it required UnmanagedCode permission
			_AppObjects = new HttpStaticObjectsCollection (this);
			_SessionObjects = new HttpStaticObjectsCollection (this);
			_Lock = new ReaderWriterLock ();
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:7,代码来源:HttpApplicationState.cs

示例13: CreatLog

 /// <summary>
 ///     创建日志文件
 /// </summary>
 private void CreatLog() {
     TextWriter logwrite = null;
     var writelock = new ReaderWriterLock();
     try {
         writelock.AcquireWriterLock(-1);
         var directoryInfo = m_fileinfo.Directory;
         if (directoryInfo != null && !directoryInfo.Exists) {
             var directory = m_fileinfo.Directory;
             if (directory != null) directory.Create();
         }
         logwrite = TextWriter.Synchronized(m_fileinfo.CreateText());
         logwrite.WriteLine("#------------------------------------------------------");
         logwrite.WriteLine("#     SYSTEM LOG                                  ");
         logwrite.WriteLine("#                                                      ");
         logwrite.WriteLine("#     Create at " + DateTime.Now.ToString(CultureInfo.InvariantCulture) + "   ");
         logwrite.WriteLine("#                                                      ");
         logwrite.WriteLine("#------------------------------------------------------");
         logwrite.Close();
     }
     catch (Exception ex) {
         throw new Exception("创建系统日志文件出错!" + ex);
     }
     finally {
         writelock.ReleaseWriterLock();
         if (logwrite != null) {
             logwrite.Close();
         }
     }
 }
开发者ID:kangwl,项目名称:KANG.Frame,代码行数:32,代码来源:Log.cs

示例14: RaceClassesStore

        public RaceClassesStore()
        {
            _loaded = false;
            _cache = null;

            _lock = new ReaderWriterLock();
        }
开发者ID:anxkha,项目名称:DRM,代码行数:7,代码来源:RaceClassesStore.cs

示例15: UpBuffer

 public UpBuffer(string string_0)
 {
     this.list_0 = new List<int>(30);
     this.readerWriterLock_0 = new ReaderWriterLock();
     this.hashtable_0 = Hashtable.Synchronized(new Hashtable(0xa3));
     this.AlarmCodeList = string_0;
 }
开发者ID:lexzh,项目名称:Myproject,代码行数:7,代码来源:UpBuffer.cs


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