/// <summary> /// Returns false when (a) the specified AsyncWrite value already exists or (b) the queue is full /// </summary> /// <param name="w"></param> /// <param name="writerDelegate"></param> /// <returns></returns> public bool QueueAsync(AsyncWrite w, AsyncWriterDelegate writerDelegate) { lock (_sync) { if (GetQueuedBufferBytes() + w.GetBufferLength() > MaxQueueBytes) { return(false); //Because we would use too much ram. } if (c.ContainsKey(w.Key)) { return(false); //We already have a queued write for this data. } c.Add(w.Key, w); Task.Run( async() => { await writerDelegate(w); Remove(w); }).ConfigureAwait(false); return(true); } }
/// <summary> /// Returns false when (a) the specified AsyncWrite value already exists, (b) the queue is full, or (c) the thread pool queue is full /// </summary> /// <param name="w"></param> /// <returns></returns> public bool Queue(AsyncWrite w, WriterDelegate writerDelegate) { lock (_sync) { if (GetQueuedBufferBytes() + w.GetBufferLength() > MaxQueueBytes) { return(false); //Because we would use too much ram. } if (c.ContainsKey(HashTogether(w.RelativePath, w.ModifiedDateUtc))) { return(false); //We already have a queued write for this data. } if (!ThreadPool.QueueUserWorkItem(delegate(object state){ AsyncWrite job = state as AsyncWrite; writerDelegate(job); }, w)) { return(false); //thread pool refused } return(true); } }
/// <summary> /// Returns false when (a) the specified AsyncWrite value already exists, (b) the queue is full, or (c) the thread pool queue is full /// </summary> /// <param name="w"></param> /// <param name="writerDelegate"></param> /// <returns></returns> public bool Queue(AsyncWrite w, WriterDelegate writerDelegate) { lock (_sync) { if (GetQueuedBufferBytes() + w.GetBufferLength() > MaxQueueBytes) { return(false); //Because we would use too much ram. } if (c.ContainsKey(w.Key)) { return(false); //We already have a queued write for this data. } c.Add(w.Key, w); if (!ThreadPool.QueueUserWorkItem(delegate(object state) { AsyncWrite job = state as AsyncWrite; writerDelegate(job); Remove(job); }, w)) { return(false); //thread pool refused } return(true); } }
/// <summary> /// Returns false when (a) the specified AsyncWrite value already exists, (b) the queue is full, or (c) the thread pool queue is full /// </summary> /// <param name="w"></param> /// <returns></returns> public bool Queue(AsyncWrite w,WriterDelegate writerDelegate ) { lock (_sync) { if (GetQueuedBufferBytes() + w.GetBufferLength() > MaxQueueBytes) return false; //Because we would use too much ram. if (c.ContainsKey(HashTogether(w.RelativePath, w.ModifiedDateUtc))) return false; //We already have a queued write for this data. if (!ThreadPool.QueueUserWorkItem(delegate(object state){ AsyncWrite job = state as AsyncWrite; writerDelegate(job); }, w)) return false; //thread pool refused return true; } }