本文整理汇总了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();
}
示例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;
}
示例3: RoleStore
public RoleStore()
{
_loaded = false;
_cache = new List<Role>();
_lock = new ReaderWriterLock();
}
示例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);
}
示例5: RaidInstanceStore
public RaidInstanceStore()
{
_loaded = false;
_cache = new List<RaidInstance>();
_lock = new ReaderWriterLock();
}
示例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();
}
}
示例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);
}
示例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;
}
}
示例9: SpecializationStore
public SpecializationStore()
{
_loaded = false;
_cache = new List<Specialization>();;
_lock = new ReaderWriterLock();
}
示例10: ExpansionStore
public ExpansionStore()
{
_loaded = false;
_cache = null;
_lock = new ReaderWriterLock();
}
示例11: InitializeConfiguration
public override void InitializeConfiguration()
{
_Entities = new IdentityMap();
_Scalars = new Dictionary<string,object>();
_Loads = new Hashtable();
_RWL = new ReaderWriterLock();
}
示例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 ();
}
示例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();
}
}
}
示例14: RaceClassesStore
public RaceClassesStore()
{
_loaded = false;
_cache = null;
_lock = new ReaderWriterLock();
}
示例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;
}