Beispiel #1
0
        public IDisposable StartPrecacheThread()
        {
            PrecacheThread newThread = null;

            try
            {
                newThread = new PrecacheThread(this);
                var oldPrecache = Interlocked.CompareExchange(ref precache_, newThread, NullPrecache.Instance);
                if (!ReferenceEquals(oldPrecache, NullPrecache.Instance))
                {
                    throw new InvalidOperationException("Precache thread is aleady running.");
                }

                return(newThread);
            }
            catch (Exception ex)
            {
                try
                {
                    newThread?.Dispose();
                }
                catch (Exception cleanupEx)
                {
                    throw new AggregateException(ex, cleanupEx);
                }

                throw;
            }
        }
Beispiel #2
0
 private void OnPrecacheThreadStop(PrecacheThread thread)
 => Interlocked.CompareExchange(ref precache_, NullPrecache.Instance, thread);