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


C# ConcurrentQueue.ToList方法代码示例

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


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

示例1: CheckEncryptedMessages

        public void CheckEncryptedMessages()
        {
            var transportMessages = new ConcurrentQueue<TransportMessage>();

            _transportTap.MessageReceived += transportMessages.Enqueue;
            _transportTap.MessageSent += transportMessages.Enqueue;

            var gotMessage = new ManualResetEvent(false);

            _activator.Handle<string>(async message =>
            {
                if (message != "hej") throw new ArgumentException("not the right message!!");

                gotMessage.Set();
            });

            _activator.Bus.SendLocal("hej").Wait();

            gotMessage.WaitOrDie(TimeSpan.FromSeconds(3));

            var messages = transportMessages.ToList();

            Assert.That(messages.Count, Is.EqualTo(2));

            var headers = messages.First().Headers;

            Assert.That(headers[EncryptionHeaders.ContentEncryption], Is.EqualTo("silly"));
        }
开发者ID:RichieYang,项目名称:Rebus,代码行数:28,代码来源:TestCustomEncryption.cs

示例2: RegisterTypeAsParallel

        /// <summary>
        ///		<para><see cref="IFrameworkContainer"/> 컨테이너에 등록할 개체를 Task Parallel Library 를 이용하여 병렬로 처리합니다.</para>
        ///		<para>단, 컨테이너에 개체를 등록할 때 CPU Process 의 개수를 이용하여 등록합니다.</para>
        ///		<para>단, 오버헤드가 높을 수 있는 작업이므로 <see cref="IFrameworkContainer"/> 의 내부적인 모든 작업을 병렬화 합니다.</para>
        ///		<para>단, 병렬 작업은 .NET Framework 4.0 빌드에서만 동작합니다.</para>
        /// </summary>
        /// <param name="container"></param>
        /// <param name="action"></param>
        public static void RegisterTypeAsParallel(this IFrameworkContainer container, IEnumerable<Action> action)
        {
            ConcurrentQueue<Exception> exceptions = null;
            try
            {
                exceptions = new ConcurrentQueue<Exception>();

                try
                {
                    action.AsParallel()
                            .WithDegreeOfParallelism(Environment.ProcessorCount)
                            .WithExecutionMode(ParallelExecutionMode.ForceParallelism)
                            .ForAll( o => o());

                }
                catch (Exception ex)
                {
                    exceptions.Enqueue(ex);
                }
            }
            catch (Exception)
            {
                if( exceptions != null )
                    exceptions.ToList().ForEach( o => Trace.WriteLine( o.Message ));

                throw;
            }
        }
开发者ID:powerumc,项目名称:UmcCore,代码行数:36,代码来源:FrameworkContainerExtensions.cs

示例3: GetBuildings

        public async Task<MineResult> GetBuildings()
        {
            var buildInfos =  await GetBuldingsByCoords();
            
            var buildings = new ConcurrentQueue<Building>();
            var warnings = new ConcurrentQueue<String>();
            var tasks = new List<Task>();
            var i = 0;
            foreach (var buildInfo in buildInfos) {
                tasks.Add(Task.Run(async () => {
                    try {
                        buildings.Enqueue(await GetBuilding(buildInfo));
                        Logger.Instance.Info(String.Format("{0}/{1}: {2} ({3}-{4})", i++, buildInfos.Count(), buildInfo.name, buildInfo.id, buildInfo.url));
                    }
                    catch (Exception ex) {
                        var msg = String.Format("Не удалось получить информацию по {0} ({1}-{2})", buildInfo.name, buildInfo.id, buildInfo.url);
                        Logger.Instance.Error(msg, ex);
                        warnings.Enqueue(msg);
                    }
                }));

                await Task.Delay(Settings.Default.MskGureRequestDelay);
            }
            Task.WaitAll(tasks.ToArray());

            return new MineResult()
            {
                Buildings = buildings.ToList(),
                Warnings = warnings.ToList()
            };
        }
开发者ID:alpospb,项目名称:Mining,代码行数:31,代码来源:MskGuruMiner.cs

示例4: GetCities

        async Task<List<String>> GetCities()
        {
           /*
           /// TESTCODE
           return await Task.Run<List<String>>(() =>
           {
               return new List<string>() { "http://sfo.spr.ru/novokuznetsk-i-novokuznetskiy-rayon/transport/avtobazi-avtokolonni-avtotransportnie/" };
           });
           */
           

            var tasks = new List<Task>();
            var regionUrls = GetRegionUrls();

            var index = 0;
            var cityUrls = new ConcurrentQueue<String>();
            foreach (var regionUrl in regionUrls)
            //var regionUrl = regionUrls.First();
            {
                tasks.Add(TasksExecuteHelper.Execute(new ExecuteParams()
                {
                    AttemptsCount = 3,
                    RequestFunction = async (url, proxy, step) =>
                    {
                        foreach (var cityUrl in await GetCitiesUrl(url))
                            cityUrls.Enqueue(cityUrl);

                        Logger.Instance.Info(String.Format("{0}/{1} Загружены города из региона {2}", step, cityUrls.Count, url));
                    },
                    ExceptionAction = (url, proxy, step, ex) =>
                    {
                        Logger.Instance.Error(String.Format("{0}/{1} Ошибка при загрузке городов из региона {2}", step, cityUrls.Count, url));
                    },
                    Step = ++index,
                    Url = regionUrl,
                    TimeInterval = new TimeSpan(0, 0, 1)
                }));

                await Task.Delay(Properties.Settings.Default.SprCityRequestDelay);
            }

            Task.WaitAll(tasks.ToArray());

            return cityUrls.ToList();
        }
开发者ID:alpospb,项目名称:Mining,代码行数:45,代码来源:SprMiner.cs

示例5: WriteQuery4Data

 public static void WriteQuery4Data(string file)
 {
     var results = new ConcurrentQueue<string>();
       results.Enqueue(string.Format("keyword1\tkeyword2\tkeyword3\tkeyword4\tResults.Count\t" +
        "UKP_Pagerank\tUKP_LKP\tpagerank_LKP\t" +
      "kenDalLKP_RCM\tkenDalpagerank_RCM\t" +
     "UKP_Pagerank_concord\tUKP_Pagerank_discord\t" +
     "UKP_LKP_concord\tUKP_LKP_discord\t" +
     "pagerank_LKP_concord\tpagerank_LKP_discord" +
     "LKP_RCM_concord\tLKP_RCM_discord" +
     "pagerank_RCM_concord\tpagerank_RCM_discord\r\n"));
       Parallel.ForEach(dicQuery4.Values, x =>
       {
     results.Enqueue(x.ToString());
       });
       File.WriteAllText(Path.GetFullPath(directory + "\\result-" +
       file), string.Concat(results.ToList()));
 }
开发者ID:haihoi2,项目名称:KeywordSimilarity,代码行数:18,代码来源:Program.cs

示例6: WriteResultToFile

 static void WriteResultToFile(int step, string file)
 {
     StringBuilder sb = new StringBuilder();
       var results = new ConcurrentQueue<string>();
       Parallel.ForEach(dicSpaceStateValues, x =>
       {
     results.Enqueue(string.Format("\"{0}\",\"{1}\",\"{2}\"\n", x.Key.Key, x.Key.Value, x.Value));
       });
       File.WriteAllText(Path.GetFullPath(directory + "\\result-round-" +
       step.ToString() +"-"+file + ".csv"), string.Concat(results.ToList()));
 }
开发者ID:haihoi2,项目名称:KeywordSimilarity,代码行数:11,代码来源:Program.cs

示例7: GetBuildings

        MineResult GetBuildings(List<BuildingShortInfo> buildShortInfos)
        {
            var buildings = new ConcurrentQueue<Building>();
            var warnings = new ConcurrentQueue<String>();
            var tasks = new List<Task>();
            var i = 0;
            foreach (var buildInfo in buildShortInfos)
            {
                i++;

                tasks.Add(Task.Run(async () =>
                {
                    var currentStep = i;
                    var buildingUrl = "http://mosnovostroy.ru" + buildInfo.Url;

                    try
                    {
                        var html = await HttpHelper.HttpGet(buildingUrl);
                        var building = new Building()
                        {
                            Latitude = buildInfo.Latitude,
                            Longitude = buildInfo.Longitude,
                            Url = buildingUrl
                        };

                        ParseHtmlForBuilding(html, building);

                        buildings.Enqueue(building);

                        Logger.Instance.Info(String.Format("{0}/{1} Получена информация по дому {2}", currentStep.ToString(), buildShortInfos.Count, buildingUrl));
                    } catch (Exception ex)
                    {
                        var msg = String.Format("{0}/{1} При получении информации по дому {2} возникла ошибка!", currentStep.ToString(), buildShortInfos.Count, buildingUrl);
                        Logger.Instance.Error(msg, ex);
                        warnings.Enqueue(msg);
                    }
                }));

                Task.Delay(Settings.Default.MosnovostroyRequestDelay).Wait();
            }
            Task.WaitAll(tasks.ToArray());

            return new MineResult()
            {
                Buildings = buildings.ToList(), 
                Warnings = warnings.ToList()
            };
        }
开发者ID:alpospb,项目名称:Mining,代码行数:48,代码来源:MosnovostroyMiner.cs

示例8: SingleStepReduce


//.........这里部分代码省略.........

							if (lastPerformedReduceType != ReduceType.MultiStep)
								continue;

                            if ( Log.IsDebugEnabled )
                            {
                                Log.Debug("Key {0} was moved from multi step to single step reduce, removing existing reduce results records", reduceKey);
                            }

							using (StopwatchScope.For(removeReduceResultsDuration))
							{
                                // now we are in single step but previously multi step reduce was performed for the given key
                                var mappedBuckets = actions.MapReduce.GetMappedBuckets(index.IndexId, reduceKey, token);        

                                // add scheduled items too to be sure we will delete reduce results of already deleted documents
								foreach (var mappedBucket in mappedBuckets.Union(scheduledItemsMappedBuckets))
								{
									actions.MapReduce.RemoveReduceResults(index.IndexId, 1, reduceKey, mappedBucket);
									actions.MapReduce.RemoveReduceResults(index.IndexId, 2, reduceKey, mappedBucket / 1024);
								}
							}
						}

						parallelStats.Operations.Add(PerformanceStats.From(IndexingOperation.Reduce_RemoveReduceResults, removeReduceResultsDuration.ElapsedMilliseconds));

						parallelOperations.Enqueue(parallelStats);
					});
				});

				reduceLevelStats.Operations.Add(new ParallelPerformanceStats
				{
					NumberOfThreads = parallelOperations.Count,
					DurationMs = (long)(SystemTime.UtcNow - parallelProcessingStart).TotalMilliseconds,
					BatchedOperations = parallelOperations.ToList()
				});

				var getMappedResultsDuration = new Stopwatch();				

				var reductionPerformanceStats = new List<IndexingPerformanceStats>();
                
                var keysLeftToReduce = new HashSet<string>(keysToReduce);                                              
				while (keysLeftToReduce.Count > 0)
				{
                    var keysReturned = new HashSet<string>();       

                    // Try to diminish the allocations happening because of .Resize()
                    var mappedResults = new List<MappedResultInfo>(keysLeftToReduce.Count);                             
                    
                    context.TransactionalStorage.Batch(actions =>
					{
						var take = context.CurrentNumberOfItemsToReduceInSingleBatch;

						using (StopwatchScope.For(getMappedResultsDuration))
						{
                            mappedResults = actions.MapReduce.GetMappedResults(index.IndexId, keysLeftToReduce, true, take, keysReturned, token, mappedResults);
						}
					});

					var count = mappedResults.Count;

                    int size = 0;
                    foreach ( var item in mappedResults )
                    {
                        item.Bucket = 0;
                        size += item.Size;
                    }
开发者ID:nwendel,项目名称:ravendb,代码行数:67,代码来源:ReducingExecuter.cs

示例9: Run

        public void Run()
        {
            var data = _matchDataDriver.GetMatchLinksToScrap(DateTime.Now.AddDays(1), "[Ss][Pp][Oo][Rr].*[Tt][Oo][Tt][Oo].*[Ss][UÜuü][Pp][Ee][Rr].*[Ll][Iİiı][Gg]", "[Pp][Tt][Tt].*1.*[Ll][Iİiı][Gg]").ToList();

            totalToScrap = data.Count;

            Stopwatch watch = Stopwatch.StartNew();

            ConcurrentQueue<object> modelQueue = new ConcurrentQueue<object>();
            ConcurrentQueue<Tuple<string, string>> sourceQueue = new ConcurrentQueue<Tuple<string, string>>();

            List<List<BsonDocument>> dataSplit = new List<List<BsonDocument>>();
            List<Thread> threadList = new List<Thread>();

            int pageSize = 10;
            int maxPageCount = 10;

            int pageCount = data.Count / pageSize;
            if(pageCount > maxPageCount)
            {
                pageSize = data.Count / maxPageCount;
                pageCount = data.Count / pageSize;
            }
            int lastPageSize = data.Count % pageSize;
            for(int i = 0; i < pageCount; i++)
            {
                dataSplit.Add(data.Skip(pageSize * i).Take(pageSize).ToList());
            }
            if(lastPageSize > 0)
            {
                dataSplit.Add(data.Skip(pageSize * pageCount).ToList());
            }
            
            for(int i = 0; i < dataSplit.Count; i++)
            {
                Dictionary<string, object> parameters = new Dictionary<string, object>();
                parameters.Add("data", dataSplit[i]);
                parameters.Add("modelQueue", modelQueue);
                parameters.Add("sourceQueue", sourceQueue);
                parameters.Add("dispatcher", _dispatcher);

                Thread thread = new Thread(new ParameterizedThreadStart(ThreadStart));
                //thread.IsBackground = true;
                thread.SetApartmentState(ApartmentState.STA);
                thread.Start(parameters);
                threadList.Add(thread);
            }

            for(int i = 0; i < threadList.Count; i++)
            {
                threadList[i].Join();
            }

            watch.Stop();

            Console.WriteLine(string.Format("Total exception : {0}", exceptionCount));
            Console.WriteLine(watch.ElapsedMilliseconds);

            _matchDataDriver.InsertMatchData(modelQueue.ToArray());
            _dataSourceDriver.UpdateStatus(sourceQueue.ToList());

            Console.WriteLine("*** FINISHED ***");
        }
开发者ID:emrahoner,项目名称:WebSuctioner,代码行数:63,代码来源:TffMatchInfoScraper.cs

示例10: UsingParallelFor

 public void UsingParallelFor()
 {
     ConcurrentQueue<DataItem> values = new ConcurrentQueue<DataItem>();
     Parallel.For(0, _list.Count, i =>
     {
         if (_list[i].SomeInt == SAMPLE)
         {
                 values.Enqueue(_list[i]);
         }
     });
     var result = values.ToList();
 }
开发者ID:Coderik,项目名称:NGauge,代码行数:12,代码来源:Filtering.cs

示例11: WriteResultToFile

 private static void WriteResultToFile(string directory, string file)
 {
     StringBuilder sb = new StringBuilder();
       var results1 = new ConcurrentQueue<string>();
       Parallel.ForEach(dicAllPapers, x =>
       {
     results1.Enqueue(string.Format("\"{0}\",\"{1}\",\"{2}\"\n", x.Key, x.Value.curValue, x.Value.conference));
       });
       File.WriteAllText(Path.GetFullPath(directory + file + "-papers.csv"), string.Concat(results1.ToList()));
       var results2 = new ConcurrentQueue<string>();
       Parallel.ForEach(dicAllAuthors, x =>
       {
     results2.Enqueue(string.Format("\"{0}\",\"{1}\",\"{2}\"\n", x.Key, x.Value.curValue, x.Value.authorName));
       });
       File.WriteAllText(Path.GetFullPath(directory + file + "-authors.csv"), string.Concat(results2.ToList()));
       var results3 = new ConcurrentQueue<string>();
       Parallel.ForEach(dicAllConferences, x =>
       {
     results3.Enqueue(string.Format("\"{0}\",\"{1}\",\"{2}\"\n", x.Key, x.Value.curValue, x.Value.conferenceName));
       });
       File.WriteAllText(Path.GetFullPath(directory + file + "-conferences.csv"), string.Concat(results3.ToList()));
 }
开发者ID:haihoi2,项目名称:KeywordSimilarity,代码行数:22,代码来源:Utilities.cs

示例12: UsingParallelFor

 public void UsingParallelFor()
 {
     ConcurrentQueue<String> values = new ConcurrentQueue<String>();
     Parallel.For(0, _list.Count, i =>
     {
         values.Enqueue(_list[i].SomeString);
     });
     var result = values.ToList();
 }
开发者ID:Coderik,项目名称:NGauge,代码行数:9,代码来源:Transforming.cs

示例13: GetAtpUrls

        async Task<List<String>> GetAtpUrls(List<String> regionUrls)
        {
            var index = 0;
            var atpUrls = new ConcurrentQueue<String>();
            var tasks = new List<Task>();
            foreach (var regionUrl in regionUrls)
            //var regionUrl = regionUrls.First();
            {
                var executeParams = new ExecuteParams()
                {
                    Step = ++index,
                    Url = regionUrl,
                    TimeInterval = new TimeSpan(0, 0, 1),
                    AttemptsCount = 3,
                    RequestFunction = async (url, proxy, step) =>
                    {
                        var html = await HttpHelper.HttpGet(url);

                        foreach (var atpUrl in ParseAtpUrlsFromPage(html))
                            atpUrls.Enqueue(atpUrl);

                        Logger.Instance.Info(String.Format("{0}/{1} получено страниц с АТП {2}", step, regionUrls.Count, url));
                    },
                    ExceptionAction = (url, proxy, step, ex) =>
                    {
                        Logger.Instance.Error("Не удалось получить страницу с АТП " + url, ex);
                    }
                };

                tasks.Add(TasksExecuteHelper.Execute(executeParams));

                await Task.Delay(Properties.Settings.Default.OrgPageRegionRequestDelay);
            }

            Task.WaitAll(tasks.ToArray());

            return atpUrls.ToList();
        }
开发者ID:alpospb,项目名称:Mining,代码行数:38,代码来源:OrgPageMiner.cs

示例14: EditRecording

        public EditRecording(ConcurrentQueue<string> actionQueue )
        {
            tempList = actionQueue.ToList();
            InitializeComponent();
            bool firstMove = true;
            int count = 0;
            string moveAction = string.Empty;
            ps = new PointScreen();
            int testFirstXCoord, testFirstYCoord, testSecondXCoord, testSecondYCoord;
            testFirstXCoord = testFirstYCoord = testSecondXCoord = testSecondYCoord = 0;
            foreach(string action in tempList)
            {
                if (action.StartsWith("[") && action.EndsWith("];"))
                {
                    double seconds = Convert.ToInt64(action.Replace("];", "").Replace("[", ""));
                    seconds = TimeSpan.FromMilliseconds(seconds).TotalSeconds;
                    //ActionList.Items.Add(string.Format("Wait for {0} seconds", seconds));
                }
                else if (action.StartsWith("{") && action.EndsWith("};"))
                {
                    if (firstMove)
                    {
                        string tempAction = action.Replace("{", "").Replace("};", "");
                        testFirstXCoord = Convert.ToInt32(tempAction.Substring(0, tempAction.IndexOf(",")));
                        testFirstYCoord = Convert.ToInt32(tempAction.Substring(tempAction.IndexOf(",") + 2));
                        moveAction += string.Format("Move from X: {0} Y: {1} to ",
                            tempAction.Substring(0, tempAction.IndexOf(",")),
                            tempAction.Substring(tempAction.IndexOf(",") + 2));
                        firstMove = false;
                    }
                }
                else if (mouseActions.Contains(action.Replace(";", "")))
                {
                    string lastMove = string.Empty;
                    if (tempList[count - 1].Contains("{"))
                    {
                        lastMove = tempList[count - 1];
                    }
                    else if (tempList[count - 2].Contains("{"))
                    {
                        lastMove = tempList[count - 2];
                    }

                    if (!string.IsNullOrEmpty(lastMove))
                    {
                        string tempAction = lastMove.Replace("{", "").Replace("};", "");
                        testSecondXCoord = Convert.ToInt32(tempAction.Substring(0, tempAction.IndexOf(",")));
                        testSecondYCoord = Convert.ToInt32(tempAction.Substring(tempAction.IndexOf(",") + 2));
                        moveAction += string.Format("X: {0} Y: {1}",
                            tempAction.Substring(0, tempAction.IndexOf(",")),
                            tempAction.Substring(tempAction.IndexOf(",") + 2));

                        if (testFirstXCoord != testSecondXCoord && testFirstYCoord != testSecondYCoord)
                        {
                            ActionList.Items.Add(moveAction);
                        }
                        testFirstXCoord = testSecondXCoord = testFirstYCoord = testSecondYCoord = 0;
                        moveAction = string.Empty;
                        firstMove = true;
                    }

                    if (action.Replace(";", "") == "LCU")
                    {
                        ActionList.Items.Add("Left Click");
                    }
                    else if (action.Replace(";", "") == "RCU")
                    {
                        ActionList.Items.Add("Right Click");
                    }
                }
                else if (action.StartsWith("(") && action.EndsWith(");"))
                {
                    ActionList.Items.Add(string.Format("Press the {0} key.",
                        ((VirtualKeyCode) Convert.ToInt32(action.Replace("(", "").Replace(");", "")))));
                }

                count++;
            }
        }
开发者ID:Mritter26,项目名称:MouseRecorder,代码行数:79,代码来源:EditRecording.cs

示例15: UsingParallelFor

 public void UsingParallelFor()
 {
     var queue = new ConcurrentQueue<DataTriplet>();
     Parallel.ForEach(_listA, a =>
     {
         foreach (var b in _listB)
         {
             foreach (var c in _listC)
             {
                 var item = new DataTriplet(a, b, c);
                 queue.Enqueue(item);
             }
         }
     });
     var list = queue.ToList();
 }
开发者ID:Coderik,项目名称:NGauge,代码行数:16,代码来源:FromFroming.cs


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