Parallel static sınıfı

z

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ParallelSamples
{
    class Program
    {
        static void Main(string[] args)
        {
            var tonbalam= new ConcurrentBag<int>();
            var listem = new List<int>();
            Parallel.For(1, 100, tonbalam.Add);
            Parallel.For(1, 100, listem.Add);
            Console.WriteLine("\r\ntonbalam------------");
            int cekilen;// bir sayı atanıp bu sayının çekilmesi denenebilir.
            if (tonbalam.TryTake(out cekilen))
            {
                Console.WriteLine(" çekilen Ve silinen sayı: {0}", cekilen);
            }
            int cekilen2;

            //ayrı iş parçaıkları ile çalıştığından bazen hata oluşabilir.
            if (tonbalam.TryPeek(out cekilen2))
            {
                Console.WriteLine(" çekilen  sayı: {0}", cekilen2);
            }

            foreach (int item in tonbalam)
            {
                Console.Write("{0}\t", item);
            }
            Console.WriteLine("\r\nlistem------------");
            foreach (int item in listem)
            {
                Console.Write("{0}\t", item);
            }



            //ikinci örnek, parametre olarak bir delege verilmiştir.
            Console.WriteLine("\r\n---------------");
            Parallel.For(1, 100,  x => { 
                Console.Write("{0}\t ", x+1);
            });


        }
    }
}

z

Ayrıntılı bilgiyi buradan inceleyebilirsiniz.

z

 

Add comment

The file '/Custom/Widgets/Calendar/widget.cshtml' does not exist.The file '/Custom/Widgets/Category list/widget.cshtml' does not exist.The file '/Custom/Widgets/Tag cloud/widget.cshtml' does not exist.The file '/Custom/Widgets/Page List/widget.cshtml' does not exist.The file '/Custom/Widgets/Month List/widget.cshtml' does not exist.