Пример #1
0
        public void Parallele_Ausführung() {
            var multipliziere1 = new Multipliziere_mit_sich_selbst();
            var multipliziere2 = new Multipliziere_mit_sich_selbst();
            var scatter = new Scatter<double>();
            var gather = new Gather<double>();

            scatter.Output1 += multipliziere1.Process;
            scatter.Output2 += multipliziere2.Process;
            multipliziere1.Result += gather.Input1;
            multipliziere2.Result += gather.Input2;

            var waitHandle = new AutoResetEvent(false);
            IEnumerable<double> result = null;
            gather.Result += x => {
                result = x;
                waitHandle.Set();
            };

            var dauer = Stopuhr.Starten(() => {
                scatter.Process(Zahlen(10000000));
                waitHandle.WaitOne();
                result.Last();
            });

            Console.WriteLine(dauer);
        }
Пример #2
0
        public Form1() {
            InitializeComponent();

            var scatter = new Scatter<int>();

            scatter.Output1 += x => {
                foreach (var t in x) {
                    Thread.Sleep(10);
                    if (listBox1.InvokeRequired) {
                        listBox1.Invoke(new MethodInvoker(() => listBox1.Items.Add(t)));
                    }
                    else {
                        listBox1.Items.Add(t);
                    }
                }
            };
            scatter.Output2 += x => {
                foreach (var t in x) {
                    Thread.Sleep(10);
                    if (listBox2.InvokeRequired) {
                        listBox2.Invoke(new MethodInvoker(() => listBox2.Items.Add(t)));
                    }
                    else {
                        listBox2.Items.Add(t);
                    }
                }
            };

            scatter.Process(Values());
        }
Пример #3
0
        private static void Main(string[] args) {
            var scatter = new Scatter<int>();

            //scatter.Output1 += x => {
            //    foreach (var t in x) {
            //        Console.WriteLine("#1: {0}", t);
            //    }
            //};
            //scatter.Output2 += x => {
            //    foreach (var t in x) {
            //        Console.WriteLine("#2: {0}", t);
            //    }
            //};

            //scatter.Process(Values());
            //Console.ReadLine();

            var gather = new Gather<int>();
            var worker1 = new Logger<int>();
            var worker2 = new Logger<int>();
            scatter.Output1 += worker1.Process;
            worker1.Result += gather.Input1;
            scatter.Output2 += worker2.Process;
            worker2.Result += gather.Input2;
            gather.Result += x => {
                foreach (var t in x) {
                    Console.WriteLine("#0: {0}", t);
                }
            };
            scatter.Process(Values());

            Console.ReadLine();
        }