Ejemplo n.º 1
0
        public Stream OpenStream(TKey item, long?size, bool onlyIfAlreadyAvailable = false)
        {
            lock (streams)
            {
                streams.TryGetValue(item, out var ms);
                if (ms != null)
                {
                    lock (ms)
                    {
                        if (!ms.IsDisposed)
                        {
                            return(ms.CreateStream());
                        }
                    }
                }

                if (onlyIfAlreadyAvailable)
                {
                    return(null);
                }

                ms            = new MemoryStreamManager(stream => load(item, stream), size);
                streams[item] = ms;
                return(ms.CreateStream());

                //Console.WriteLine("  (" + access + ")");
            }
        }
Ejemplo n.º 2
0
 public ConsumerStream(MemoryStreamManager memoryStreamManager)
 {
     this.memoryStreamManager = memoryStreamManager;
     memoryStreamManager.IncrementUsage();
     id = Interlocked.Increment(ref lastId);
     //Console.WriteLine("Open: " + id);
 }