public void _05_01_ThreadsMit2DelegatesTest() { Basics._04_Objektorientiert.StoppUhr st = new Basics._04_Objektorientiert.StoppUhr(); st.Start(); const long ende = 10000000; DGps dgPrimscan = new DGps(mko.Algo.NumberTheory.PrimeFactors.scan); var ares1 = dgPrimscan.BeginInvoke(1, ende / 2, null, null); var ares2 = dgPrimscan.BeginInvoke(ende/2 +1, ende , null, null); while (!ares1.IsCompleted && !ares2.IsCompleted) { Debug.Write("."); System.Threading.Thread.Sleep(200); } // Ergebnisse abrufen var lst1 = dgPrimscan.EndInvoke(ares1); var lst2 = dgPrimscan.EndInvoke(ares2); st.Stopp(); Debug.WriteLine("Anz gefundener Primzahlen: " + (lst1.Count() + lst2.Count()) + " Zeit: " + st.ZeitInMs()); }
public void _05_01_ThreadsMit4DelegatesTest() { const long ende = 10000000; Basics._04_Objektorientiert.StoppUhr st = new Basics._04_Objektorientiert.StoppUhr(); st.Start(); DGps dgPrimscan = new DGps(mko.Algo.NumberTheory.PrimeFactors.scan); var ares1 = dgPrimscan.BeginInvoke(1, ende / 4, null, null); var ares2 = dgPrimscan.BeginInvoke(ende / 4 + 1, ende/2, null, null); var ares3 = dgPrimscan.BeginInvoke(ende / 2 + 1, (3*ende)/4, null, null); var ares4 = dgPrimscan.BeginInvoke((3 * ende) / 4 + 1, ende, null, null); // Warten, solange bis fertig //ares1.AsyncWaitHandle.WaitOne(); while (!ares1.IsCompleted && !ares2.IsCompleted && !ares3.IsCompleted && !ares4.IsCompleted) { Debug.Write("."); System.Threading.Thread.Sleep(200); } // Ergebnisse abrufen var lst1 = dgPrimscan.EndInvoke(ares1); var lst2 = dgPrimscan.EndInvoke(ares2); var lst3 = dgPrimscan.EndInvoke(ares3); var lst4 = dgPrimscan.EndInvoke(ares4); st.Stopp(); Debug.WriteLine("Anz gefundener Primzahlen: " + (lst1.Count() + lst2.Count() + lst3.Count() + lst4.Count()) + " Zeit: " + st.ZeitInMs()); }