• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Threading.ReaderWriterLock类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: SyntaxCatalog

 static SyntaxCatalog()
 {
     m_timeoutForSyntaxesLock = TimeSpan.FromSeconds(10);
     m_syntaxesLock = new ReaderWriterLock();
     m_syntaxesByIdOrAlias = new SortedDictionary<string, Syntax>(StringComparer.OrdinalIgnoreCase);
     m_lockForCatalogLoad = new object();
 }
开发者ID:svermeulen,项目名称:iris,代码行数:7,代码来源:SyntaxCatalog.cs


示例17: BlibDb

 private BlibDb(String path)
 {
     FilePath = path;
     SessionFactory = BlibSessionFactoryFactory.CreateSessionFactory(path, false);
     DatabaseLock = new ReaderWriterLock();
     _progressStatus = new ProgressStatus(string.Empty);
 }
开发者ID:lgatto,项目名称:proteowizard,代码行数:7,代码来源:BlibDb.cs


示例18: DatabaseResource

 private DatabaseResource(string path)
 {
     Path = path;
     _refCount = 1;
     SessionFactory = SessionFactoryFactory.CreateSessionFactory(path, ProteomeDb.TYPE_DB, false);
     DatabaseLock = new ReaderWriterLock();
 }
开发者ID:lgatto,项目名称:proteowizard,代码行数:7,代码来源:DatabaseResource.cs


示例19: InstrumentedAssembly

		static InstrumentedAssembly()
		{
			InstrumentedAssembly.readerWriterLock = new ReaderWriterLock();
			InstrumentedAssembly.mapIDToPublishedObject = new Hashtable();
			InstrumentedAssembly.mapPublishedObjectToID = new Hashtable();
			InstrumentedAssembly.upcountId = 0xeff;
		}
开发者ID:nickchal,项目名称:pash,代码行数:7,代码来源:InstrumentedAssembly.cs


示例20: CharacterStore

        public CharacterStore()
        {
            _loaded = false;
            _cache = new List<Character>();

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Threading.ReaderWriterLockSlim类代码示例发布时间:2022-05-26
下一篇:
C# Threading.Overlapped类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap