Example #1
0
 /// <summary>
 ///     Resets the singleton, this is required for unit testing.
 /// </summary>
 public static new void Reset()
 {
     lock (ThreadSafeLock)
     {
         _retriever = null;
     }
 }
Example #2
0
        /// <summary>
        ///     Returns a singleton instance of <c>LabelRetriever</c>.
        /// </summary>
        /// <param name="language"></param>
        /// <returns><c>LabelRetriever</c></returns>
        /// <seealso href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/lock-statement"/>
        public static new LabelRetriever GetLabelRetriever(Languages language = null)
        {
            if (_retriever == null)
            {
                // lock will prevent multiple threads from attempting to create the singleton.
                lock (ThreadSafeLock)
                {
                    // should check conditional again, after lock is released the singleton would have been creates=d during a previous thread.
                    if (_retriever == null)
                    {
                        _retriever = new LabelRetriever(language);
                    }
                }
            }

            return(_retriever);
        }