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


C# ConcurrentStack.PushRange方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            //Stack - Pilha (LIFO) 
            ConcurrentStack<int> stack = new ConcurrentStack<int>();
            //Adiciona um item na pilha
            stack.Push(42);

            int result;
     
            //metodo trypop retorna o ultimo item a ser adicionado na lista, caso não tenha mais item ele não dar por que ele "tenta(try)" pega um item
            //quando usar o metodo trypop o item é removido da coleção
            if (stack.TryPop(out result))
            {
                Console.WriteLine("Popped: {0}", result);
            }
            if (stack.TryPop(out result))
            {
                Console.WriteLine("Popped: {0}", result);
            }

            stack.PushRange(new int[] { 1, 2, 3 });

            int[] values = new int[2];
            //metod retorna uma coleção de itens da pilha
            stack.TryPopRange(values);

            foreach (var item in values)
            {
                Console.WriteLine(item);
            }

            Console.ReadLine();
        }
开发者ID:Willamar,项目名称:ExamRef-70-483,代码行数:33,代码来源:Program.cs

示例2: Main

        static void Main(string[] args)
        {
            ConcurrentStack<int> stack = new ConcurrentStack<int>();

            stack.Push(42);

            int result;
            if (stack.TryPop(out result))
            {
                Console.WriteLine(result);
            }

            stack.PushRange(new int[] { 1, 2, 3 });

            int[] values = new int[2];
            stack.TryPopRange(values);

            foreach (var i in values)
            {
                Console.WriteLine(i);
            }

            Console.Write("Press a key to exit");
            Console.ReadKey();
        }
开发者ID:jbijoux,项目名称:Exam70_483,代码行数:25,代码来源:Program.cs

示例3: ConcurrentStackExampleRange

		public int ConcurrentStackExampleRange ()
		{
			var stack = new ConcurrentStack<int> (); 

			stack.PushRange (new int[] { 1, 2, 3 }); 
		
			return stack.TryPopRange (new int[2]); 
		}
开发者ID:caloggins,项目名称:DOT-NET-on-Linux,代码行数:8,代码来源:ConcurrentStackExample.cs

示例4: ExclusiveConnectionStrategy

 /// <summary>
 /// Initializes the strategy with the specified nodes and cluster configuration
 /// </summary>
 /// <param name="nodes"> The nodes. </param>
 /// <param name="config"> The config. </param>
 public ExclusiveConnectionStrategy(Ring nodes, CqlConnectionStringBuilder config)
 {
     _nodes = nodes;
     _config = config;
     _connections = new ConcurrentStack<Connection>();
     _rndGen = new Random((int)DateTime.UtcNow.Ticks);
     _connectionCount = _nodes.Sum(n => n.ConnectionCount);
     if(_connectionCount > 0)
         _connections.PushRange(_nodes.SelectMany(n => n).ToArray());
 }
开发者ID:reuzel,项目名称:CqlSharp,代码行数:15,代码来源:ExclusiveConnectionStrategy.cs

示例5: ActualizeAllArticlesAsync

        public Task ActualizeAllArticlesAsync()
        {
            return ExecuteSafe(async () =>
            {
                await Initialize();

                if (!await _permissionsService.CanDownload())
                    return;

                var queue = new ConcurrentQueue<FeedModel>();
                foreach (var activeSource in SourceManager.GetActiveSources())
                    foreach (var activeFeed in activeSource.ActiveFeeds)
                        queue.Enqueue(activeFeed);

                var setting = await _settingsRepository.GetSettingByKeyAsync(SettingKey.ConcurrentThreads);
                var threadNumber = setting is IntSettingModel ? ((IntSettingModel)setting).IntValue : 5;

                var threads = new List<Task>();

                if (await _permissionsService.CanDownloadFeeds())
                {
                    _progressService.Start(ProgressType.Feed, queue.Count);
                    for (int i = 0; i < threadNumber; i++)
                    {
                        threads.Add(DoFeedQueue(queue));
                    }
                    await Task.WhenAll(threads.ToArray());
                    _progressService.Stop(ProgressType.Feed);
                    threads.Clear();
                }
                
                if (await _permissionsService.CanDownloadArticles())
                {
                    var stack = new ConcurrentStack<ArticleModel>();
                    foreach (var activeSource in SourceManager.GetActiveSources())
                        foreach (var activeFeed in activeSource.ActiveFeeds)
                        {
                            var news = activeFeed.AllArticles.Where(a => a.LoadingState < LoadingState.Loaded).ToArray();
                            if (news.Length > 0)
                                stack.PushRange(news);
                        }
                    //reverse stack so 
                    stack = new ConcurrentStack<ArticleModel>(stack.Reverse());

                    _progressService.Start(ProgressType.Article, stack.Count);
                    for (int i = 0; i < threadNumber; i++)
                    {
                        threads.Add(DoArticleStack(stack));
                    }
                    await Task.WhenAll(threads.ToArray());
                    _progressService.Stop(ProgressType.Article);
                    threads.Clear();
                }
            });
        }
开发者ID:famoser,项目名称:OfflineMedia,代码行数:55,代码来源:AktualizeArticles.cs

示例6: Run

        public void Run()
        {
            ConcurrentStack<int> stack = new ConcurrentStack<int>();
            stack.Push(42);

            int result;
            if (stack.TryPop(out result))
                Console.WriteLine("Popped: {0}", result);

            stack.PushRange(new int[] { 1, 2, 3 });
            int[] values = new int[2];
            stack.TryPopRange(values);

            foreach (int i in values)
                Console.WriteLine(i);
        }
开发者ID:vikramadhav,项目名称:Certification_70-483,代码行数:16,代码来源:Listing_1_32.cs

示例7: RunConcurrentStack

        private void RunConcurrentStack()
        {
            Console.WriteLine("Stack Run implementation along with Range implementations");
            ConcurrentStack<int> stack = new ConcurrentStack<int>();
            stack.Push(10);

            int result;
            if (stack.TryPop(out result))
                Console.WriteLine(result);

            stack.PushRange(new int[] { 1, 2, 3 ,4});

            int[] values = new int[4];
            Console.WriteLine(stack.TryPopRange(values));

            foreach (int num in values) Console.WriteLine(num);
        }
开发者ID:mayankaggarwal,项目名称:MyConcepts,代码行数:17,代码来源:Concept19.cs

示例8: Main

        private static void Main()
        {
            var stack = new ConcurrentStack<int>();
            stack.Push(42);

            int result;
            if (stack.TryPop(out result)) {
                Console.WriteLine(result);
            }

            stack.PushRange(new[] {1, 2, 3});
            var values = new int[2];
            stack.TryPopRange(values);

            foreach (var i in values) {
                Console.WriteLine(i);
            }

            Console.ReadLine();
        }
开发者ID:DriesPeeters,项目名称:examprep-70_483,代码行数:20,代码来源:Program.cs

示例9: Main

        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            ConcurrentStack<int> stack = new ConcurrentStack<int>();
            stack.Push(42);

            int result;
            if (stack.TryPop(out result))
                Console.WriteLine("Popped: {0}", result);

            stack.PushRange(new int[] { 1, 2, 3 });

            int[] values = new int[2];
            stack.TryPopRange(values);

            foreach (int i in values)
                Console.WriteLine(i);

            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
开发者ID:vmp,项目名称:CSharpExamples,代码行数:22,代码来源:Program.cs

示例10: Main

        static void Main(string[] args)
        {
            ConcurrentStack<int> stack = new ConcurrentStack<int>();
            stack.Push(67);

            int result;
            if (stack.TryPop(out result))
                Console.WriteLine("Popped: {0}", result);
            stack.PushRange(new int[] { 1, 2, 3 });
            int[] values = new int[2];
            stack.TryPopRange(values);
            foreach (int i in values)
                Console.WriteLine(i);

            Console.WriteLine("\n\n----------------------------------------------------------------------\n\n");
            Console.ReadLine();

            var dict = new ConcurrentDictionary<string, int>();
            if (dict.TryAdd("ERHAN",26))
            {
                Console.WriteLine("Added");
            }
            if (dict.TryUpdate("ERHAN", 30, 26))
            {
                Console.WriteLine("26 updated to 30");
            }

            dict["ERHAN"] = 32; // Overwrite unconditionally

            Console.WriteLine("----------------------------------------------------------------------");
            Console.ReadLine();

            int r = dict.AddOrUpdate("ERHAN", 35, (S, I) => I * 2);
            Console.WriteLine(r);
            int r2 = dict.GetOrAdd("ERHAN", 37);

            Console.WriteLine("----------------------------------------------------------------------");
            Console.ReadLine();
        }
开发者ID:ErhanGDC,项目名称:MyWorks,代码行数:39,代码来源:Program.cs

示例11: EnumerateTypeTrees

        public static IEnumerable<Type> EnumerateTypeTrees(this IEnumerable<Type> rootTypes)
        {
            if(rootTypes == null) yield break;

            var alreadyChecked = new HashSet<Type>();
            var stack = new ConcurrentStack<Type>(rootTypes);

            Type currentType;
            while (stack.TryPop(out currentType))
            {
                if (alreadyChecked.Contains(currentType)) continue;

                alreadyChecked.Add(currentType);
                yield return currentType;

                var extractedTypes = currentType.ExtractTypes();
                if (extractedTypes.Length > 0)
                {
                    stack.PushRange(extractedTypes);
                }
            }
        }
开发者ID:Chatham,项目名称:ServiceStack.Text.TupleSerializer,代码行数:22,代码来源:TypeExtensions.cs

示例12: Main

        public static void Main(string[] args)
        {
            ConcurrentStack<int> stack = new ConcurrentStack<int>();

            stack.Push(42);

            int result;
            if (stack.TryPop(out result))
            {
                Console.WriteLine("Popped: {0}", result);
            }

            stack.PushRange(new int[] { 1, 2, 3 });

            int[] values = new int[2];
            stack.TryPopRange(values);

            foreach (var i in values)
            {
                Console.WriteLine(i);
            }

            Console.ReadLine();
        }
开发者ID:nissbran,项目名称:Training-Certifications,代码行数:24,代码来源:Program.cs

示例13: PushRangeTestCase

		public void PushRangeTestCase()
		{
			var testStack = new ConcurrentStack<int>();
			
			var testData = new int[] { 1, 2, 3, 4, 5 };			
			testStack.PushRange (testData);
			
			Assert.AreEqual (testData.Length, testStack.Count);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:9,代码来源:ConcurrentStackTests.cs

示例14: WriteFloodAndBatchTogether

        bool WriteFloodAndBatchTogether(CommandProcessorContext context, int timeOut, int batchSize,
            int batchThreadCount, int floodThreadCount)
        {
            string streamId = Guid.NewGuid().ToString();
            const string batchMsg = "BasicVerify-Batch-Test-Message";
            const string floodMsg = "BasicVerify-Flood-Test-Message";
            int batchCount = 0;
            int floodCount = 0;

            DateTime dt = DateTime.MaxValue;
            var errors = new ConcurrentStack<string>();
            var threads = new List<Task>();

            for (int t = 0; t < batchThreadCount; t++)
            {
                var task = Task.Factory.StartNew(() =>
                {
                    while (DateTime.Now < dt)
                    {
                        try
                        {
                            context.Client.EventStores.WriteEventsInLargeBatch(streamId,
                            Enumerable.Range(0, batchSize).Select(
                                x =>
                                {
                                    var bytes = Encoding.UTF8.GetBytes(batchMsg);
                                    return (bytes);
                                }));
                            Interlocked.Add(ref batchCount, 1);
                        }
                        catch (Exception ex)
                        {
                            errors.Push(ex.Message);
                        }

                    }
                }, TaskCreationOptions.LongRunning | TaskCreationOptions.PreferFairness);
                threads.Add(task);
            }

            for (int t = 0; t < floodThreadCount; t++)
            {
                var task = Task.Factory.StartNew(() =>
                    {
                        while (DateTime.Now < dt)
                        {
                            try
                            {
                                context.Client.EventStores.WriteEvent(streamId, Encoding.UTF8.GetBytes(floodMsg));
                                Interlocked.Add(ref floodCount, 1);
                            }
                            catch (Exception ex)
                            {
                                errors.Push(ex.Message);
                            }
                        }
                    }, TaskCreationOptions.LongRunning | TaskCreationOptions.PreferFairness);
                threads.Add(task);
            }

            dt = DateTime.Now.AddSeconds(timeOut);
            Task.WaitAll(threads.ToArray());

            context.Log.Info("Add {0} flood messages", floodCount);
            context.Log.Info("Add {0} batch", batchCount);

            var readErrors = ReadAddMessages(context, streamId, batchMsg, floodMsg, batchCount * batchSize, floodCount).ToArray();

            if (readErrors.Any())
                errors.PushRange(readErrors);

            foreach (var err in errors.ToArray())
                context.Log.Error(err);

            return errors.Count == 0;
        }
开发者ID:Lokad,项目名称:lokad-data-platform,代码行数:76,代码来源:BasicVerifyProcessor.cs

示例15: RunConcurrentStackTest6_PushRange

        //Tests COncurrentSTack.PushRange
        private static bool RunConcurrentStackTest6_PushRange(int NumOfThreads, int localArraySize)
        {
            TestHarness.TestLog("* RunConcurrentStackTest6_PushRange({0},{1})", NumOfThreads, localArraySize);
            ConcurrentStack<int> stack = new ConcurrentStack<int>();

            Thread[] threads = new Thread[NumOfThreads];
            for (int i = 0; i < threads.Length; i++)
            {
                threads[i] = new Thread((obj) =>
                {
                    int index = (int)obj;
                    int[] array = new int[localArraySize];
                    for (int j = 0; j < localArraySize; j++)
                    {
                        array[j] = index + j;
                    }

                    stack.PushRange(array);
                });

                threads[i].Start(i * localArraySize);

            }

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

            //validation
            for (int i = 0; i < threads.Length; i++)
            {
                int lastItem = -1;
                for (int j = 0; j < localArraySize; j++)
                {
                    int currentItem = 0;
                    if (!stack.TryPop(out currentItem))
                    {
                        TestHarness.TestLog(" > Failed, TryPop returned false");
                        return false;
                    }
                    if (lastItem > -1 && lastItem - currentItem != 1)
                    {
                        TestHarness.TestLog(" > Failed {0} - {1} shouldn't be consecutive", lastItem, currentItem);
                    }

                    lastItem = currentItem;

                }
            }

            return true;
        }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:54,代码来源:CdsTests.cs


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