Files
Umbraco-CMS/src/Umbraco.Core/WriteLock.cs

35 lines
1.0 KiB
C#
Raw Normal View History

2018-06-29 19:52:40 +02:00
using System;
using System.Threading;
namespace Umbraco.Cms.Core
2018-06-29 19:52:40 +02:00
{
/// <summary>
/// Provides a convenience methodology for implementing locked access to resources.
/// </summary>
/// <remarks>
/// <para>Intended as an infrastructure class.</para>
2019-01-22 18:03:39 -05:00
/// <para>This is a very inefficient way to lock as it allocates one object each time we lock,
2018-06-29 19:52:40 +02:00
/// so it's OK to use this class for things that happen once, where it is convenient, but not
/// for performance-critical code!</para>
/// </remarks>
public class WriteLock : IDisposable
{
private readonly ReaderWriterLockSlim _rwLock;
/// <summary>
/// Initializes a new instance of the <see cref="WriteLock"/> class.
/// </summary>
/// <param name="rwLock">The rw lock.</param>
public WriteLock(ReaderWriterLockSlim rwLock)
{
_rwLock = rwLock;
_rwLock.EnterWriteLock();
}
void IDisposable.Dispose()
{
_rwLock.ExitWriteLock();
}
}
}