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


C# ConcurrentSet类代码示例

本文整理汇总了C#中ConcurrentSet的典型用法代码示例。如果您正苦于以下问题:C# ConcurrentSet类的具体用法?C# ConcurrentSet怎么用?C# ConcurrentSet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: should_test_that_an_item_is_contained

        public void should_test_that_an_item_is_contained()
        {
            var setToRemoveFrom = new ConcurrentSet<int>(Enumerable.Range(1, 5));

            setToRemoveFrom.Contains(3).ShouldBeTrue();
            setToRemoveFrom.Contains(7).ShouldBeFalse();
        }
开发者ID:MarouenK,项目名称:Zebus,代码行数:7,代码来源:ConcurrentSetTests.cs

示例2: CreateProjectMapAsync

        private async Task<ProjectMap> CreateProjectMapAsync(ConcurrentSet<SymbolAndProjectId> symbols)
        {
            using (Logger.LogBlock(FunctionId.FindReference_CreateProjectMapAsync, _cancellationToken))
            {
                var projectMap = new ProjectMap();

                var scope = _documents?.Select(d => d.Project).ToImmutableHashSet();
                foreach (var symbolAndProjectId in symbols)
                {
                    foreach (var finder in _finders)
                    {
                        _cancellationToken.ThrowIfCancellationRequested();

                        var projects = await finder.DetermineProjectsToSearchAsync(symbolAndProjectId.Symbol, _solution, scope, _cancellationToken).ConfigureAwait(false);
                        foreach (var project in projects.Distinct().WhereNotNull())
                        {
                            if (scope == null || scope.Contains(project))
                            {
                                projectMap.Add(project, (symbolAndProjectId, finder));
                            }
                        }
                    }
                }

                Contract.ThrowIfTrue(projectMap.Any(kvp => kvp.Value.Count != kvp.Value.ToSet().Count));
                return projectMap;
            }
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:28,代码来源:FindReferencesSearchEngine_MapCreation.cs

示例3: HandleReduceForIndex

		protected void HandleReduceForIndex(IndexToWorkOn indexToWorkOn)
		{
			var viewGenerator = context.IndexDefinitionStorage.GetViewGenerator(indexToWorkOn.IndexId);
			if (viewGenerator == null)
				return;

			bool operationCanceled = false;
			var itemsToDelete = new ConcurrentSet<object>();

			IList<ReduceTypePerKey> mappedResultsInfo = null;
			transactionalStorage.Batch(actions =>
			{
				mappedResultsInfo = actions.MapReduce.GetReduceTypesPerKeys(indexToWorkOn.IndexId,
					context.CurrentNumberOfItemsToReduceInSingleBatch,
					context.NumberOfItemsToExecuteReduceInSingleStep).ToList();
			});

			var singleStepReduceKeys = mappedResultsInfo.Where(x => x.OperationTypeToPerform == ReduceType.SingleStep).Select(x => x.ReduceKey).ToArray();
			var multiStepsReduceKeys = mappedResultsInfo.Where(x => x.OperationTypeToPerform == ReduceType.MultiStep).Select(x => x.ReduceKey).ToArray();

			currentlyProcessedIndexes.TryAdd(indexToWorkOn.IndexId, indexToWorkOn.Index);
			try
			{
				if (singleStepReduceKeys.Length > 0)
				{
					Log.Debug("SingleStep reduce for keys: {0}",singleStepReduceKeys.Select(x => x + ","));
					SingleStepReduce(indexToWorkOn, singleStepReduceKeys, viewGenerator, itemsToDelete);
				}

				if (multiStepsReduceKeys.Length > 0)
				{
					Log.Debug("MultiStep reduce for keys: {0}", singleStepReduceKeys.Select(x => x + ","));
					MultiStepReduce(indexToWorkOn, multiStepsReduceKeys, viewGenerator, itemsToDelete);
				}
			}
			catch (OperationCanceledException)
			{
				operationCanceled = true;
			}
			finally
			{
				if (operationCanceled == false)
				{
					// whatever we succeeded in indexing or not, we have to update this
					// because otherwise we keep trying to re-index failed mapped results
					transactionalStorage.Batch(actions =>
					{
						var latest = actions.MapReduce.DeleteScheduledReduction(itemsToDelete);

						if (latest == null)
							return;
						actions.Indexing.UpdateLastReduced(indexToWorkOn.Index.indexId, latest.Etag, latest.Timestamp);
					});
				}

				Index _;
				currentlyProcessedIndexes.TryRemove(indexToWorkOn.IndexId, out _);
			}
		}
开发者ID:bbqchickenrobot,项目名称:ravendb,代码行数:59,代码来源:ReducingExecuter.cs

示例4: RabbitMqPollingNode

		/// <summary>
		/// Create a work item queue that will try to pull items from a named RabbitMQ endpoint
		/// </summary>
		/// <param name="endpoint">Destination endpoint to pull messages from</param>
		/// <param name="messagingBase">RabbitMQ connection provider</param>
		/// <param name="sleeper">Sleeper to rate limit polling</param>
		public RabbitMqPollingNode(IRoutingEndpoint endpoint,
			IMessagingBase messagingBase, ISleepWrapper sleeper)
		{
			_endpoint = endpoint.ToString();
			_messagingBase = messagingBase;
			_sleeper = sleeper;
			_boundMessageTypes = new ConcurrentSet<Type>();
		}
开发者ID:i-e-b,项目名称:SevenDigital.Messaging,代码行数:14,代码来源:RabbitMqPollingNode.cs

示例5: should_add_an_item

        public void should_add_an_item()
        {
            var setToRemoveFrom = new ConcurrentSet<int>(Enumerable.Range(1, 5));

            setToRemoveFrom.Add(6);

            setToRemoveFrom.ShouldEqual(new[] { 1, 2, 3, 4, 5, 6 });
        }
开发者ID:MarouenK,项目名称:Zebus,代码行数:8,代码来源:ConcurrentSetTests.cs

示例6: should_clear_itself

        public void should_clear_itself()
        {
            var setToClear = new ConcurrentSet<int>(Enumerable.Range(1, 5));

            setToClear.Clear();

            setToClear.Count.ShouldEqual(0);
        }
开发者ID:MarouenK,项目名称:Zebus,代码行数:8,代码来源:ConcurrentSetTests.cs

示例7: should_remove_an_item

        public void should_remove_an_item()
        {
            var setToRemoveFrom = new ConcurrentSet<int>(Enumerable.Range(1, 5));

            setToRemoveFrom.Remove(3);

            setToRemoveFrom.ShouldEqual(new[] { 1, 2, 4, 5 });
        }
开发者ID:MarouenK,项目名称:Zebus,代码行数:8,代码来源:ConcurrentSetTests.cs

示例8: WatcherInfo

        public WatcherInfo(FileSystemWatcher watcher, Boolean isDirectory)
            : this()
        {
            Watcher = watcher;

            if (isDirectory)
                WatchedFiles = new ConcurrentSet<String>();
        }
开发者ID:aleksandrpak,项目名称:solutions,代码行数:8,代码来源:WatcherInfo.cs

示例9: LocalQueuePollingNode

		/// <summary>
		/// Create a local polling node.
		/// <para>You should not use this yourself. Use:</para>
		/// <para>MessagingSystem.Configure.WithLocalQueue(...);</para>
		/// and receive messages as normal.
		/// </summary>
		public LocalQueuePollingNode(string dispatchPath, string incomingPath,
		                             IMessageSerialiser serialiser, ISleepWrapper sleeper)
		{
			_dispatchPath = dispatchPath;
			_incomingPath = incomingPath;
			_serialiser = serialiser;
			_sleeper = sleeper;
			_boundMessageTypes = new ConcurrentSet<Type>();
		}
开发者ID:i-e-b,项目名称:SevenDigital.Messaging,代码行数:15,代码来源:LocalQueuePollingNode.cs

示例10: should_copy_itself_to_an_array

        public void should_copy_itself_to_an_array()
        {
            var setToCopy = new ConcurrentSet<int>(Enumerable.Range(1, 5));
            var destinationArray = new int[5];

            setToCopy.CopyTo(destinationArray, 0);

            destinationArray.ShouldEqual(new[] { 1, 2, 3, 4, 5 });
        }
开发者ID:MarouenK,项目名称:Zebus,代码行数:9,代码来源:ConcurrentSetTests.cs

示例11: GetItemsToReduceParams

		public GetItemsToReduceParams(string index, IEnumerable<string> reduceKeys, int level, bool loadData, ConcurrentSet<object> itemsToDelete)
		{
			Index = index;
			Level = level;
			LoadData = loadData;
			ItemsToDelete = itemsToDelete;
			ItemsAlreadySeen = new HashSet<Tuple<string, int>>();
			ReduceKeys = new HashSet<string>(reduceKeys);
		}
开发者ID:925coder,项目名称:ravendb,代码行数:9,代码来源:IMappedResultsStorageAction.cs

示例12: RunAsync

      public async Task RunAsync() {
         Console.WriteLine(DateTime.Now);
         const int kMessagesPerWorker = 200000;
         var sink = courierFacades[0];
         var senders = courierFacades.Skip(1).ToArray();
         var counter = kMessagesPerWorker * senders.Length;
         var doneSignal = new AsyncLatch();
         int upCounter = 0;
         var set = new ConcurrentSet<int>();
         sink.InboundMessageRouter.RegisterHandler<string>(
            x => {
               set.AddOrThrow(int.Parse(x.Body));
               var newCounter = Interlocked.Decrement(ref counter);
               Interlocked.Increment(ref upCounter);
               if (upCounter % 500 == 0)
                  Console.WriteLine(newCounter + " " + upCounter);
               if (newCounter == 0) {
                  doneSignal.Set();
               }
               return Task.FromResult(false);
            });

         var sync = new AsyncCountdownLatch(senders.Length);
         var senderTasks = senders.Select((s, id) => Go(async () => {
            await s.PeerTable.GetOrAdd(sink.Identity.Id).WaitForDiscoveryAsync().ConfigureAwait(false);
            sync.Signal();
            await sync.WaitAsync().ConfigureAwait(false);
            Console.WriteLine("Sink discovered: " + DateTime.Now);

            const int kBatchFactor = 1;
            for (var batch = 0; batch < kBatchFactor; batch++) {
               var batchSize = kMessagesPerWorker / kBatchFactor;
               await Task.WhenAll(Util.Generate(
                  batchSize,
                  i => s.Messenger.SendReliableAsync(
                     "" + (batch * batchSize + i + id * kMessagesPerWorker),
                     sink.Identity.Id))
                  ).ConfigureAwait(false);
            }

            Console.WriteLine("Worker Done: " + DateTime.Now);
         }));
         await Task.WhenAll(senderTasks).ConfigureAwait(false);
         Console.WriteLine("Senders Done: " + DateTime.Now);

         await doneSignal.WaitAsync().ConfigureAwait(false);
         Console.WriteLine("Done Signalled: " + DateTime.Now);

         AssertCollectionDeepEquals(set, new ConcurrentSet<int>(Enumerable.Range(0, kMessagesPerWorker * senders.Length)));

         while (true) {
            GC.Collect();
         }
      }
开发者ID:the-dargon-project,项目名称:courier,代码行数:54,代码来源:MessagingLoadTests.cs

示例13: CompilationWithAnalyzers

        /// <summary>
        /// Creates a new compilation by attaching diagnostic analyzers to an existing compilation.
        /// </summary>
        /// <param name="compilation">The original compilation.</param>
        /// <param name="analyzers">The set of analyzers to include in future analyses.</param>
        /// <param name="options">Options that are passed to analyzers.</param>
        /// <param name="cancellationToken">A cancellation token that can be used to abort analysis.</param>
        public CompilationWithAnalyzers(Compilation compilation, ImmutableArray<DiagnosticAnalyzer> analyzers, AnalyzerOptions options, CancellationToken cancellationToken)
        {
            if (compilation == null)
            {
                throw new ArgumentNullException(nameof(compilation));
            }

            VerifyAnalyzersArgument(analyzers);

            _cancellationToken = cancellationToken;
            _exceptionDiagnostics = new ConcurrentSet<Diagnostic>();
            _driver = AnalyzerDriver.Create(compilation, analyzers, options, AnalyzerManager.Instance, AddExceptionDiagnostic, false, out _compilation, _cancellationToken);
        }
开发者ID:anshita-arya,项目名称:roslyn,代码行数:20,代码来源:CompilationWithAnalyzers.cs

示例14: CodeLensFindReferencesProgress

        public CodeLensFindReferencesProgress(
            ISymbol queriedDefinition,
            SyntaxNode queriedNode,
            int searchCap,
            CancellationToken cancellationToken)
        {
            _queriedSymbol = queriedDefinition;
            _queriedNode = queriedNode;
            _aggregateCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
            _locations = new ConcurrentSet<Location>();

            SearchCap = searchCap;
        }
开发者ID:tvsonar,项目名称:roslyn,代码行数:13,代码来源:CodeLensFindReferenceProgress.cs

示例15: CreateProjectMapAsync

        private async Task<ConcurrentDictionary<Project, ConcurrentQueue<ValueTuple<SymbolAndProjectId, IReferenceFinder>>>> CreateProjectMapAsync(
            ConcurrentSet<SymbolAndProjectId> symbols)
        {
            using (Logger.LogBlock(FunctionId.FindReference_CreateProjectMapAsync, _cancellationToken))
            {
                Func<Project, ConcurrentQueue<ValueTuple<SymbolAndProjectId, IReferenceFinder>>> createQueue = 
                    p => new ConcurrentQueue<ValueTuple<SymbolAndProjectId, IReferenceFinder>>();

                var projectMap = new ConcurrentDictionary<Project, ConcurrentQueue<ValueTuple<SymbolAndProjectId, IReferenceFinder>>>();

#if PARALLEL
            Roslyn.Utilities.TaskExtensions.RethrowIncorrectAggregateExceptions(cancellationToken, () =>
                {
                    symbols.AsParallel().WithCancellation(cancellationToken).ForAll(s =>
                    {
                        finders.AsParallel().WithCancellation(cancellationToken).ForAll(f =>
                        {
                            var projects = f.DetermineProjectsToSearch(s, solution, cancellationToken) ?? SpecializedCollections.EmptyEnumerable<Project>();
                            foreach (var project in projects.Distinct())
                            {
                                projectMap.GetOrAdd(project, createQueue).Enqueue(ValueTuple.Create(s, f));
                            }
                        });
                    });
                });
#else

                var scope = _documents != null ? _documents.Select(d => d.Project).ToImmutableHashSet() : null;
                foreach (var s in symbols)
                {
                    foreach (var f in _finders)
                    {
                        _cancellationToken.ThrowIfCancellationRequested();

                        var projects = await f.DetermineProjectsToSearchAsync(s.Symbol, _solution, scope, _cancellationToken).ConfigureAwait(false);
                        foreach (var project in projects.Distinct().WhereNotNull())
                        {
                            if (scope == null || scope.Contains(project))
                            {
                                projectMap.GetOrAdd(project, createQueue).Enqueue(ValueTuple.Create(s, f));
                            }
                        }
                    }
                }
#endif

                Contract.ThrowIfTrue(projectMap.Any(kvp => kvp.Value.Count != kvp.Value.ToSet().Count));
                return projectMap;
            }
        }
开发者ID:jkotas,项目名称:roslyn,代码行数:50,代码来源:FindReferencesSearchEngine_MapCreation.cs


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