コード例 #1
0
        //
        // Initialized a reference or value type using a factory method
        // and specifiyng the amount of spin cycles that a thread executes
        // before block.
        //

        public static T EnsureInitialized <T>(ref T target, ref StInitOnceLock initLock,
                                              Func <T> factory, int spinCount)
        {
            if (initLock.TryInit(spinCount))
            {
                try {
                    target = factory();
                    initLock.InitCompleted();
                } catch {
                    initLock.InitFailed();
                    throw;
                }
            }
            return(target);
        }
コード例 #2
0
        //
        // Initialized a reference or value type using the default constructor,
        // blocking immediately when the init lock is busy.
        //

        public static T EnsureInitialized <T>(ref T target, ref StInitOnceLock initLock)
        {
            return(EnsureInitialized <T>(ref target, ref initLock, LazyHelper <T> .factory, 0));
        }
コード例 #3
0
        //
        // Initialized a reference or value type using a factory method,
        // blocking immediately when the init lock is busy.
        //

        public static T EnsureInitialized <T>(ref T target, ref StInitOnceLock initLock,
                                              Func <T> factory)
        {
            return(EnsureInitialized <T>(ref target, ref initLock, factory, 0));
        }