I have a multi-threaded application. Threads use ABC.Connector. I want that only one thread at a time have access to a Connector property.
class ABC
{
/// <summary>
/// Synchronization object.
/// </summary>
static object _syncObject = new object();
static DataAccess _connector;
/// <summary>
/// Global object for data access.
/// </summary>
public static DataAccess Connector
{
get
{
lock (_syncObject)
{
return _connector.CreateCopy(); // get a copy of original _connector
}
}
set
{
lock (_syncObject)
{
_connector = value;
}
}
}
}
Is it correct ?