using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ConsoleApplication7 { class Program { delegate void Tiskni(string s); static void Jednou(string s) { Console.WriteLine(s); } static void Dvakrat(string s) { Console.WriteLine("1: {0}", s); Console.WriteLine("2: {0}", s); } static DateTime start; static void VytvorNaplnASetridPole() { int MAX = 20 * 1000; int[] a = new int[MAX]; Random rnd = new Random(); for (int i = 0; i < MAX; i++) { a[i] = rnd.Next(MAX); } for (int j = 0; j < MAX; j++) { for (int i = 0; i < MAX-1; i++) { if (a[i] > a[i+1]) { int pom = a[i]; a[i] = a[i + 1]; a[i + 1] = pom; } } } TimeSpan doba = DateTime.Now - start; Console.WriteLine("{0} ms", doba.TotalMilliseconds); } static object ZAMEK = new object(); static void Main(string[] args) { new Thread(delegate() { while (true) { lock (ZAMEK) { for (int i = 0; i < 30; i++) { Console.Write('.'); } Console.WriteLine(); } } } ).Start(); new Thread(delegate() { while (true) { lock (ZAMEK) { for (int i = 0; i < 30; i++) { Console.Write('@'); } Console.WriteLine(); } } } ).Start(); Console.ReadLine(); Console.WriteLine(Environment.ProcessorCount); start = DateTime.Now; Thread th = new Thread(VytvorNaplnASetridPole); th.Start(); new Thread(VytvorNaplnASetridPole).Start(); new Thread(VytvorNaplnASetridPole).Start(); new Thread(VytvorNaplnASetridPole).Start(); new Thread(VytvorNaplnASetridPole).Start(); new Thread(VytvorNaplnASetridPole).Start(); new Thread(VytvorNaplnASetridPole).Start(); new Thread(VytvorNaplnASetridPole).Start(); new Thread(VytvorNaplnASetridPole).Start(); new Thread(VytvorNaplnASetridPole).Start(); new Thread(delegate() { VytvorNaplnASetridPole(); } ).Start(); VytvorNaplnASetridPole(); Console.ReadLine(); return; Tiskni T; T = Jednou; T += Dvakrat; T += Jednou; T += Jednou; T += Jednou; T -= Jednou; T("abcd"); Console.WriteLine("---------------"); T -= Dvakrat; T("abcd"); Console.WriteLine("---------------"); T -= Dvakrat; T("abcd"); Console.WriteLine("---------------"); T = delegate(string s) { Console.WriteLine("Tohleto vytisknu: {0}", s); } ; T += delegate(string s) { Console.WriteLine("Tohleto VYTISKNU: {0}", s); } ; T("abcd"); Console.ReadLine(); return; /* for (int k = 1; k < 100; k++) { DateTime start = DateTime.Now; string s = ""; StringBuilder sb = new StringBuilder(); for (int i = 0; i < k * 10 * 1000; i++) //s = s + 'a'; sb.Append('a'); TimeSpan doba = DateTime.Now - start; Console.WriteLine("{0}: {1} ms", k, doba.TotalMilliseconds); } Console.ReadLine(); * */ } } }