当前位置: 首页>>代码示例>>C#>>正文


C# BlockingCollection.Dispose方法代码示例

本文整理汇总了C#中BlockingCollection.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# BlockingCollection.Dispose方法的具体用法?C# BlockingCollection.Dispose怎么用?C# BlockingCollection.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BlockingCollection的用法示例。


在下文中一共展示了BlockingCollection.Dispose方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Start

        public void Start()
        {
            var ventilatorQueue = new BlockingCollection<WorkItem>();
            var sinkQueue = new BlockingCollection<WorkItem>();

            StartSink(sinkQueue);

            StartWorker(0, ventilatorQueue, sinkQueue);
            StartWorker(1, ventilatorQueue, sinkQueue);
            StartWorker(2, ventilatorQueue, sinkQueue);

            StartVentilator(ventilatorQueue);

            Thread.Sleep(1000);
            ventilatorQueue.CompleteAdding();
            sinkQueue.CompleteAdding();
            ventilatorQueue.Dispose();
            sinkQueue.Dispose();
        }
开发者ID:richard-green,项目名称:Mike.Spikes,代码行数:19,代码来源:ProducerConsumerSpike.cs

示例2: BlockingCollection

        /// <summary>
        /// Blocking collection acts as a threadsafe blocking queue
        /// </summary>
        public void BlockingCollection()
        {
            var queue = new BlockingCollection<string>();

            Task.Run(() =>
                {
                    while (true)
                    {
                        Console.Out.WriteLine(queue.Take());
                    }
                });

            for (int i = 0; i < 5; i++)
            {
                queue.Add(string.Format("item {0}", i));
                Thread.Sleep(1000);
            }

            queue.Dispose();
        }
开发者ID:mikehadlow,项目名称:Mike.Spikes,代码行数:23,代码来源:StackAndQueue.cs

示例3: Build


//.........这里部分代码省略.........
                        {
                            skipSequence = true;
                        }
                        else
                        {
                            // if the sequence contains any gap symbols then ignore the sequence.
                            foreach (byte symbol in gapSymbols)
                            {
                                for (long index = 0; index < sequence.Count; ++index)
                                {
                                    if (sequence[index] == symbol)
                                    {
                                        skipSequence = true;
                                        break;
                                    }
                                }

                                if (skipSequence)
                                    break;
                            }
                        }

                        if (skipSequence)
                        {
                            Interlocked.Increment(ref _skippedSequencesCount);
                            Interlocked.Increment(ref _processedSequencesCount);
                            continue;
                        }

                        // if the blocking collection count is exceeding 2 million kmers wait for 2 sec 
                        // so that the task can remove some kmers and create the nodes. 
                        // This will avoid OutofMemoryException
                        while (kmerDataCollection.Count > stopAddThreshold)
                        {
                            Task.Delay(TimeSpan.FromSeconds(2)).Wait();
                        }

                        // Convert sequences to k-mers
                        kmerList.AddRange(KmerData32.GetKmers(sequence, KmerLength));

                        // Most reads are <=150 basepairs, so this should avoid having to grow the list
                        // by keeping it below blockSize
                        if (kmerList.Count > addThreshold)
                        {
                            kmerDataCollection.Add(kmerList);
                            kmerList = new List<KmerData32>(4092);
                        }
                        Interlocked.Increment(ref _processedSequencesCount);
                    }

                    if (kmerList.Count <= addThreshold)
                        kmerDataCollection.Add(kmerList);
                }
                finally
                {
                    kmerDataCollection.CompleteAdding();
                }
            });

            // Consume k-mers by addding them to binary tree structure as nodes
            Parallel.ForEach(kmerDataCollection.GetConsumingEnumerable(),newKmerList=>
            {
                foreach (KmerData32 newKmer in newKmerList)
                {
                    // Create Vertex
                    DeBruijnNode node = kmerManager.SetNewOrGetOld(newKmer);

                    // Need to lock node if doing this in parallel
                    if (node.KmerCount <= 255)
                    {
                        lock (node)
                        {
                            node.KmerCount++;
                        }
                    }
                }
            });

            // Ensure producer exceptions are handled.
            producer.Wait();

            // Done filling binary tree
            kmerDataCollection.Dispose();

            //NOTE: To speed enumeration make the nodes into an array and dispose of the collection
            _nodeCount = kmerManager.NodeCount;
            _nodes = kmerManager.GenerateNodeArray();
            
            // Generate the links
            GenerateLinks(kmerManager);
            
            // Since we no longer need to search for values set left and right nodes of child array to null
            // so that they are available for GC if no longer needed
            foreach (DeBruijnNode node in _nodes)
            {
                node.Left = node.Right = null;
            }

            GraphBuildCompleted = true;
        }
开发者ID:cpatmoore,项目名称:bio,代码行数:101,代码来源:DeBruijnGraph.cs


注:本文中的BlockingCollection.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。