コード例 #1
0
        public static void Main(string[] args)
        {
            SortingUnit sortingUnit = new SortingUnit();
            CallEvent   callEvent   = new CallEvent();

            sortingUnit.SortIsFinished += callEvent.Message;
            List <string> list = new List <string>()
            {
                "Ivanov", "Petrov", "stroka", "join", "SortingUnit", "12234567898"
            };
            int left  = 0;
            int right = list.Count() - 1;
            Func <string, string, int> func = sortingUnit.CompareString;

            try
            {
                sortingUnit.NewThread(list, left, right, func);
                for (int i = 0; i < list.Count; i++)
                {
                    Console.Write("{0} ", list[i]);
                }

                Console.WriteLine();
            }
            catch (ArgumentNullException)
            {
                Console.WriteLine("Argument was null");
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: NurAliia/XT-2018Q4
        /// <summary>
        /// Create array and sort it in the second thread
        /// </summary>
        public static void Main()
        {
            string[] array = new string[] { "Hi", "hi", "a", "hello", "bye" };
            Func <string, string, int> compareString = CustomSortDemo.Program.CompareByLengthThenByAlphabet;
            SortingUnit <string>       sortingUnit   = new SortingUnit <string>(array, compareString);

            sortingUnit.SortingFinished += MethodSort;

            sortingUnit.CreateThreadForSorting();
            sync.WaitOne(); ////Waiting Event
            array = sortingUnit.Arr;
            Console.WriteLine("Main Thread");
            CustomSort.Program.Print(array);
        }
コード例 #3
0
        public static void Main(string[] args)
        {
            Console.WriteLine($"The application demonstrates a calculating in another thread.{Environment.NewLine}");
            SortingUnit.OnSort += () => sortingWaiting = false;

            IEnumerable <int> elements = CustomSort.Program.GetRandomizedIntList(75000);

            Console.WriteLine("The array was created. Press any button to start sorting...");
            Console.ReadKey();
            SortingUnit.SortingInOwnThread(elements, (a, b) => a > b);
            counter = 0;
            Console.WriteLine("Press any button to change the counter while the array is sorted...");
            while (sortingWaiting)
            {
                Console.ReadKey();
                Console.Write($"\rCounter: {counter}");
                counter++;
            }

            Console.WriteLine($"{Environment.NewLine}Sorting was end!");
        }
コード例 #4
0
ファイル: SortingUnit.cs プロジェクト: MaxiKvaksi/XT-2018Q4
 private static void Sorting <T>(IEnumerable <T> array, Func <T, T, bool> func)
 {
     SortingUnit.BubbleSort(array, func);
     OnSort();
 }