當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。