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; } }
private void OnPrecacheThreadStop(PrecacheThread thread) => Interlocked.CompareExchange(ref precache_, NullPrecache.Instance, thread);