本文整理汇总了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);
}
}
示例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)
{
}
}
示例3: Topic
public Topic(uint storeSize, TimeSpan lifespan)
{
_lifespan = lifespan;
Subscriptions = new List<ISubscription>();
Store = new MessageStore<Message>(storeSize);
SubscriptionLock = new ReaderWriterLockSlim();
}
示例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();
}
示例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();
}
示例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
}
示例7: MorphologicalFilteringOptionsViewModel
public MorphologicalFilteringOptionsViewModel()
{
StackSync = new ReaderWriterLockSlim();
if (Execute.InDesignMode)
LoadDesignTimeData();
}
示例8: NntpParser
public NntpParser(NzbConnection connection)
{
ArgumentChecker.ThrowIfNull("connection", connection);
_connection = connection;
_synchronizationObject = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
}
示例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();
}
}
示例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>();
}
示例11: ServiceHost
public ServiceHost(int servicePort)
{
pools = new List<SocketPool>();
poolsLock = new ReaderWriterLockSlim();
container = new ServiceContainer();
this.servicePort = servicePort;
}
示例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);
}
}
示例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);
}
示例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();
}
示例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();
}
});
}